-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add
ToggleButton
documentation (#4510)
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { HvToggleButton } from "@hitachivantara/uikit-react-core"; | ||
import { Favorite, FavoriteSelected } from "@hitachivantara/uikit-react-icons"; | ||
|
||
import Playground from "@docs/components/code/Playground"; | ||
import { Description } from "@docs/components/page/Description"; | ||
import { Page } from "@docs/components/page/Page"; | ||
import { getComponentData } from "@docs/utils/component"; | ||
|
||
export const getStaticProps = async ({ params }) => { | ||
const meta = await getComponentData("ToggleButton", "core", []); | ||
return { props: { ssg: { meta } } }; | ||
}; | ||
|
||
<Description /> | ||
|
||
<Page> | ||
|
||
<Playground | ||
Component={HvToggleButton} | ||
componentName="HvToggleButton" | ||
controls={{ | ||
selected: { | ||
defaultValue: false, | ||
}, | ||
disabled: { | ||
defaultValue: false, | ||
}, | ||
}} | ||
componentProps={{ | ||
notSelectedIcon: <Favorite />, | ||
selectedIcon: <FavoriteSelected />, | ||
}} | ||
/> | ||
|
||
### With tooltip | ||
|
||
You can wrap the toggle button with a tooltip to provide additional information. | ||
|
||
```tsx live | ||
import { useState } from "react"; | ||
|
||
export default function Demo() { | ||
const [selected, setSelected] = useState(false); | ||
|
||
return ( | ||
<HvTooltip title={selected ? "Turn off" : "Turn on"}> | ||
<HvToggleButton onClick={() => setSelected(!selected)}> | ||
{selected ? <LightOn /> : <LightOff />} | ||
</HvToggleButton> | ||
</HvTooltip> | ||
); | ||
} | ||
``` | ||
|
||
</Page> |