-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move more examples from SelectNextPage to example files
- Loading branch information
Showing
7 changed files
with
365 additions
and
160 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,32 @@ | ||
import { useState } from 'preact/hooks'; | ||
|
||
import { SelectNext } from '../..'; | ||
|
||
const items = [ | ||
{ id: '1', name: 'All students' }, | ||
{ id: '2', name: 'Albert Banana' }, | ||
{ id: '3', name: 'Bernard California' }, | ||
{ id: '4', name: 'Cecelia Davenport' }, | ||
{ id: '5', name: 'Doris Evanescence' }, | ||
]; | ||
|
||
export default function App() { | ||
const [value, setSelected] = useState<{ id: string; name: string }>(); | ||
|
||
return ( | ||
<div className="w-96 mx-auto"> | ||
<SelectNext | ||
aria-label="Select a person with aria label" | ||
value={value} | ||
onChange={setSelected} | ||
buttonContent={value ? value.name : <>Select one…</>} | ||
> | ||
{items.map(item => ( | ||
<SelectNext.Option value={item} key={item.id}> | ||
{item.name} | ||
</SelectNext.Option> | ||
))} | ||
</SelectNext> | ||
</div> | ||
); | ||
} |
34 changes: 34 additions & 0 deletions
34
src/pattern-library/examples/select-next-aria-labelledby.tsx
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 @@ | ||
import { useId, useState } from 'preact/hooks'; | ||
|
||
import { SelectNext } from '../..'; | ||
|
||
const items = [ | ||
{ id: '1', name: 'All students' }, | ||
{ id: '2', name: 'Albert Banana' }, | ||
{ id: '3', name: 'Bernard California' }, | ||
{ id: '4', name: 'Cecelia Davenport' }, | ||
{ id: '5', name: 'Doris Evanescence' }, | ||
]; | ||
|
||
export default function App() { | ||
const [value, setSelected] = useState<{ id: string; name: string }>(); | ||
const labelId = useId(); | ||
|
||
return ( | ||
<div className="w-96 mx-auto"> | ||
<p id={labelId}>Select a person with aria labelledby</p> | ||
<SelectNext | ||
aria-labelledby={labelId} | ||
value={value} | ||
onChange={setSelected} | ||
buttonContent={value ? value.name : <>Select one…</>} | ||
> | ||
{items.map(item => ( | ||
<SelectNext.Option value={item} key={item.id}> | ||
{item.name} | ||
</SelectNext.Option> | ||
))} | ||
</SelectNext> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.