-
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.
Merge pull request #431 from omnifed/429-docs-update-iconbutton-to-us…
…e-live-preview chore: Add live preview to icon button documentation
- Loading branch information
Showing
4 changed files
with
100 additions
and
102 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,94 @@ | ||
'use client' | ||
|
||
import CodeBuilder from '@/app/components/code-builder/code-builder' | ||
import { builder } from '@/app/components/code-builder/helpers' | ||
import { useCodeBuilder } from '@/app/context/code-builder' | ||
import { ThumbsUp } from '@cerberus-design/icons' | ||
import { IconButton } from '@cerberus-design/react' | ||
|
||
const fallbackAria = 'Like something' | ||
|
||
const api = { | ||
palette: builder.Enum('palette', ['action', 'secondaryAction', 'danger']), | ||
usage: builder.Enum('usage', ['filled', 'outlined', 'text']), | ||
size: builder.Enum('size', ['sm', 'lg']), | ||
tooltipPosition: builder.Enum('tooltipPosition', [ | ||
'top', | ||
'right', | ||
'bottom', | ||
'left', | ||
]), | ||
ariaLabel: builder.Text('ariaLabel', fallbackAria), | ||
text: builder.Text('name', 'Button'), | ||
disabled: builder.Boolean('disabled', false), | ||
} | ||
|
||
export function LivePlayground() { | ||
return ( | ||
<CodeBuilder api={api}> | ||
<IconButtonPreview /> | ||
</CodeBuilder> | ||
) | ||
} | ||
|
||
export function LivePlaygroundWithCode() { | ||
return ( | ||
<CodeBuilder | ||
api={api} | ||
code={`import { IconButton, type IconButtonProps } from '@cerberus-design/react' | ||
type MyIconButtonProps = IconButtonProps | ||
export function MyButton(props: MyIconButtonProps) { | ||
return ( | ||
<IconButton | ||
ariaLabel={{ariaLabel}} | ||
disabled={{disabled}} | ||
palette={{palette}} | ||
tooltipPosition={{tooltipPosition}} | ||
size={{size}} | ||
usage={{usage}} | ||
> | ||
<ThumbsUp /> | ||
</IconButton> | ||
) | ||
}`} | ||
> | ||
<IconButtonPreview /> | ||
</CodeBuilder> | ||
) | ||
} | ||
|
||
export function IconButtonPreview() { | ||
const { selectedProps } = useCodeBuilder() | ||
const aria = selectedProps.ariaLabel as string | ||
switch (selectedProps.palette) { | ||
case 'secondaryAction': | ||
return ( | ||
<IconButton | ||
ariaLabel={aria ?? fallbackAria} | ||
palette="secondaryAction" | ||
{...selectedProps} | ||
> | ||
<ThumbsUp /> | ||
</IconButton> | ||
) | ||
case 'danger': | ||
return ( | ||
<IconButton | ||
ariaLabel={aria ?? fallbackAria} | ||
palette="danger" | ||
{...selectedProps} | ||
> | ||
<ThumbsUp /> | ||
</IconButton> | ||
) | ||
|
||
default: | ||
return ( | ||
<IconButton ariaLabel={aria ?? fallbackAria} {...selectedProps}> | ||
<ThumbsUp /> | ||
</IconButton> | ||
) | ||
} | ||
} |
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