|
| 1 | +import React from 'react'; |
| 2 | +import Preview, { PreviewLayout } from '../Preview'; |
| 3 | +import { BooleanProperty, AlignProperty, IconsProperty, ButtonVariantProperty } from '../properties'; |
| 4 | +import type { JSX } from '@public-ui/components'; |
| 5 | +import { KolInputText, KolSplitButton, KolToolbar } from '@public-ui/react-v19'; |
| 6 | +import { translate } from '@docusaurus/Translate'; |
| 7 | + |
| 8 | +interface SplitButtonPreviewComponentProps { |
| 9 | + initialProps?: JSX.KolSplitButton; |
| 10 | + visibleProperties?: (keyof JSX.KolSplitButton)[]; |
| 11 | + codeCollapsable?: boolean; |
| 12 | + codeCollapsed?: boolean; |
| 13 | +} |
| 14 | + |
| 15 | +const toolbarItems: JSX.KolToolbar['_items'] = [ |
| 16 | + { type: 'button', _label: translate({ id: 'preview.component.split-button.menu.edit' }), _icons: { left: { icon: 'codicon-edit' } } }, |
| 17 | + { type: 'button', _label: translate({ id: 'preview.component.split-button.menu.copy' }), _icons: { left: { icon: 'codicon-copy' } } }, |
| 18 | + { type: 'button', _label: translate({ id: 'preview.component.split-button.menu.archive' }), _icons: { left: { icon: 'codicon-archive' } } }, |
| 19 | + { type: 'button', _label: translate({ id: 'preview.component.split-button.menu.delete' }), _icons: { left: { icon: 'codicon-trash' } } }, |
| 20 | +]; |
| 21 | + |
| 22 | +const SplitButtonPreview: React.FC<SplitButtonPreviewComponentProps> = (props) => { |
| 23 | + const defaultProps = React.useMemo<JSX.KolSplitButton>( |
| 24 | + () => ({ |
| 25 | + _label: translate({ id: 'preview.component.split-button.label' }), |
| 26 | + }), |
| 27 | + [], |
| 28 | + ); |
| 29 | + |
| 30 | + return ( |
| 31 | + <Preview<JSX.KolSplitButton> |
| 32 | + propertyComponents={{ |
| 33 | + _label: <KolInputText _label="Label" />, |
| 34 | + _variant: <ButtonVariantProperty label="Variant" defaultValue="normal" />, |
| 35 | + _tooltipAlign: <AlignProperty label="Tooltip Align" defaultValue="top" />, |
| 36 | + _icons: <IconsProperty label="Icons" />, |
| 37 | + _disabled: <BooleanProperty label="Disabled" />, |
| 38 | + _hideLabel: <BooleanProperty label="Hide Label" />, |
| 39 | + }} |
| 40 | + initialProps={{ ...defaultProps, ...props.initialProps }} |
| 41 | + componentName="KolSplitButton" |
| 42 | + visibleProperties={props.visibleProperties} |
| 43 | + codeCollapsable={props.codeCollapsable} |
| 44 | + codeCollapsed={props.codeCollapsed} |
| 45 | + layout={PreviewLayout.CENTERED} |
| 46 | + > |
| 47 | + {(componentProps) => ( |
| 48 | + <KolSplitButton {...componentProps}> |
| 49 | + <KolToolbar _label="" _items={toolbarItems} _orientation="vertical" /> |
| 50 | + </KolSplitButton> |
| 51 | + )} |
| 52 | + </Preview> |
| 53 | + ); |
| 54 | +}; |
| 55 | + |
| 56 | +export default SplitButtonPreview; |
0 commit comments