Skip to content

Commit

Permalink
search component and slider styles
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-figma committed Jun 10, 2024
1 parent 2e05141 commit a4d8de2
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 10 deletions.
1 change: 1 addition & 0 deletions figma.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"<FIGMA_URL_RADIO>": "https://figma.com/design/J0KLPKXiONDRssXD1AX9Oi?node-id=9762:1204",
"<FIGMA_URL_RADIOFIELD>": "https://figma.com/design/J0KLPKXiONDRssXD1AX9Oi?node-id=9762:1412",
"<FIGMA_URL_RADIOGROUP>": "https://figma.com/design/J0KLPKXiONDRssXD1AX9Oi?node-id=9762:1200",
"<FIGMA_URL_SEARCH>": "https://www.figma.com/design/J0KLPKXiONDRssXD1AX9Oi?node-id=2236-14989",
"<FIGMA_URL_SELECT>": "https://figma.com/design/J0KLPKXiONDRssXD1AX9Oi?node-id=9762:1162",
"<FIGMA_URL_SELECT_FIELD>": "https://figma.com/design/J0KLPKXiONDRssXD1AX9Oi?node-id=2136-2336",
"<FIGMA_URL_SLIDER>": "https://figma.com/design/J0KLPKXiONDRssXD1AX9Oi?node-id=3734-22471",
Expand Down
15 changes: 15 additions & 0 deletions src/stories/ui/primitives/Search.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Meta, StoryObj } from "@storybook/react";
import { Search } from "ui/primitives";

const meta: Meta<typeof Search> = {
component: Search,
title: "UI Primitives/Search",
parameters: { layout: "centered" },
};
export default meta;
type Story = StoryObj<typeof Search>;

export const Default: Story = {
args: {},
render: (args) => <Search {...args} />,
};
2 changes: 1 addition & 1 deletion src/ui/compositions/Headers/Headers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export function HeaderAuth() {
</FlexItem>
</Flex>
) : (
<ButtonGroup align="justify">{userButtons}</ButtonGroup>
<ButtonGroup align="center">{userButtons}</ButtonGroup>
)}
</Flex>
</Dialog>
Expand Down
20 changes: 20 additions & 0 deletions src/ui/primitives/Search/Search.figma.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import figma from "@figma/code-connect";
import { Search } from "./Search";

figma.connect(Search, "<FIGMA_URL_SEARCH>", {
props: {
value: figma.enum("Value Type", {
Default: figma.string("Value"),
}),
placeholder: figma.enum("Value Type", {
Default: "Placeholder here...",
Placeholder: figma.string("Value"),
}),
isDisabled: figma.enum("State", {
Disabled: true,
}),
},
example: ({ value, placeholder, isDisabled }) => (
<Search value={value} placeholder={placeholder} disabled={isDisabled} />
),
});
74 changes: 74 additions & 0 deletions src/ui/primitives/Search/Search.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { clsx } from "clsx";
import { IconSearch, IconX } from "icons";
import React, { useRef, useState } from "react";
import {
Popover as RACPopover,
type InputProps as RACInputProps,
} from "react-aria-components";
import { IconButton } from "../IconButton/IconButton";
import { Input } from "../Input/Input";
import { ListBox, ListBoxItem } from "../ListBox/ListBox";
import "./search.css";

export type SearchProps = RACInputProps & {
results?: string[];
};
export const Search = React.forwardRef(function Search(
{ className, results, ...props }: SearchProps,
ref: React.ForwardedRef<HTMLInputElement>,
) {
const [searchTerm, setSearchTerm] = useState("");
const inputRef = useRef<HTMLInputElement | null>(null);

const classNames = clsx(className, "search-input-container");

return (
<div className={classNames}>
<Input
type="search"
className="search-input"
value={searchTerm}
onInput={(e) => setSearchTerm(e.currentTarget.value)}
ref={(node) => {
inputRef.current = node;
if (typeof ref === "function") {
ref(node);
} else if (ref) {
ref.current = node;
}
}}
{...props}
/>
<span className="search-icon">
{searchTerm ? (
<IconButton
aria-label="Clear search"
onPress={() => setSearchTerm("")}
size="small"
variant="subtle"
>
<IconX />
</IconButton>
) : (
<IconButton
aria-label="Clear search"
onPress={() => inputRef?.current?.focus()}
size="small"
variant="subtle"
>
<IconSearch />
</IconButton>
)}
</span>
{results && (
<RACPopover>
<ListBox>
{results.map((a) => (
<ListBoxItem onAction={() => setSearchTerm(a)}>{a}</ListBoxItem>
))}
</ListBox>
</RACPopover>
)}
</div>
);
});
34 changes: 34 additions & 0 deletions src/ui/primitives/Search/search.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* clears the ‘X’ from Internet Explorer */
.search-input::-ms-clear {
display: none;
width: 0;
height: 0;
}
.search-input::-ms-reveal {
display: none;
width: 0;
height: 0;
}
/* clears the ‘X’ from Chrome */
.search-input::-webkit-search-decoration,
.search-input::-webkit-search-cancel-button,
.search-input::-webkit-search-results-button,
.search-input::-webkit-search-results-decoration {
display: none;
}

.search-input-container {
position: relative;
}

.search-input {
border-radius: var(--sds-size-radius-full);
padding-right: calc(var(--sds-size-padding-xxl) + var(--sds-size-padding-xs));
}

.search-icon {
position: absolute;
top: 50%;
right: var(--sds-size-padding-xs);
transform: translateY(-50%);
}
18 changes: 9 additions & 9 deletions src/ui/primitives/Slider/slider.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.slider-field {
--slider-thumb-background-color: var(--sds-color-bg-default-default);
--slider-thumb-border-color: var(--sds-color-border-brand-default);
--slider-track-background-color: var(--sds-color-bg-brand-default);
--slider-thumb-background-color: var(--sds-color-bg-brand-default);
--slider-thumb-border-color: var(--sds-color-bg-brand-default);
--slider-track-background-color: var(--sds-color-bg-brand-secondary);
font: var(--sds-font-body-base);

&[data-disabled] {
--slider-thumb-background-color: var(--sds-color-icon-disabled-default);
--slider-thumb-background-color: var(--sds-color-bg-disabled-default);
--slider-thumb-border-color: var(--sds-color-border-disabled-default);
--slider-track-background-color: var(--sds-color-bg-disabled-default);
}
Expand All @@ -14,11 +14,11 @@
/* &[data-orientation="horizontal"] { */
width: 100%;
.slider {
height: var(--sds-typography-scale-05);
height: var(--sds-size-gap-lg);
width: 100%;

&:before {
height: var(--sds-typography-scale-02);
height: var(--sds-size-gap-sm);
top: 50%;
width: 100%;
transform: translateY(-50%);
Expand All @@ -44,8 +44,8 @@
border-radius: var(--border-radius);
box-shadow: inset 0 0 0 var(--sds-size-border-width)
var(--slider-thumb-border-color);
height: var(--sds-typography-scale-05);
width: var(--sds-typography-scale-05);
height: var(--sds-size-gap-lg);
width: var(--sds-size-gap-lg);
forced-color-adjust: none;

&[data-focus-visible] {
Expand All @@ -69,9 +69,9 @@
position: relative;

&::before {
content: "";
background: var(--slider-track-background-color);
border-radius: var(--sds-size-radius-full);
content: "";
display: block;
position: absolute;
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/primitives/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export * from "./Notification/Notification";
export * from "./Pagination/Pagination";
export * from "./Popover/Popover";
export * from "./Radio/Radio";
export * from "./Search/Search";
export * from "./Select/Select";
export * from "./Slider/Slider";
export * from "./Switch/Switch";
Expand Down

0 comments on commit a4d8de2

Please sign in to comment.