-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e05141
commit a4d8de2
Showing
8 changed files
with
155 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} />, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} /> | ||
), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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%); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters