-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(PlaceholderOption): separate placeholder from useOptions fixes #45
- Loading branch information
1 parent
ab2258d
commit b2f4726
Showing
14 changed files
with
121 additions
and
75 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
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
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
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,40 @@ | ||
import { | ||
Meta, | ||
Source, | ||
Canvas, | ||
Controls, | ||
Markdown, | ||
Description, | ||
} from "@storybook/blocks"; | ||
|
||
<Meta title="components/atomic/PlaceholderOption" /> | ||
|
||
# PlaceholderOption | ||
|
||
An atomic component to be used when your `<select>` is controlled with [useSelectFieldProps](?path=/docs/hooks-useselectfieldprops--docs). | ||
Used internally in the [Select](?path=/docs/components-select--docs) component. | ||
|
||
## Usage | ||
|
||
```ts | ||
import { PlaceholderOption } from "@form-atoms/field"; | ||
``` | ||
|
||
## Features | ||
|
||
- ✅ Renders an `<option>` to appear selected while the respective `<select>` is empty. | ||
- ✅ Enables to clear a select using an optional field. | ||
|
||
## Example | ||
|
||
```tsx | ||
import { PlaceholderOption } from "@form-atoms/field"; | ||
|
||
// the placeholder must be used as the first child option: | ||
const Example = () => ( | ||
<select> | ||
<PlaceholderOption>Pick an option</PlaceholderOption> | ||
<option>regular options go after the placeholder</option> | ||
</select> | ||
); | ||
``` |
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,13 @@ | ||
import { OptionHTMLAttributes } from "react"; | ||
|
||
import { EMPTY_SELECT_VALUE } from "../../hooks"; | ||
|
||
export const PlaceholderOption = ({ | ||
children = "Please select an option", | ||
disabled = true, | ||
...props | ||
}: OptionHTMLAttributes<HTMLOptionElement>) => ( | ||
<option {...props} disabled={disabled} value={EMPTY_SELECT_VALUE}> | ||
{children} | ||
</option> | ||
); |
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 @@ | ||
export * from "./PlaceholderOption"; |
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
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
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