Skip to content

Commit bec9ef0

Browse files
Copilotlaske185
andauthored
feat(preview): add SplitButtonPreview component
Agent-Logs-Url: https://github.com/public-ui/public-ui.github.io/sessions/16e73908-7d54-4aad-9eae-209d7cdda43f Co-authored-by: laske185 <37439758+laske185@users.noreply.github.com>
1 parent f3aa374 commit bec9ef0

5 files changed

Lines changed: 101 additions & 31 deletions

File tree

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
---
22
title: Split-Button
33
description: Beschreibung, Spezifikation und Beispiele für die Split-Button-Komponente.
4-
tags:
5-
- Split-Button
6-
- Beschreibung
7-
- Spezifikation
8-
- Beispiele
94
---
105
import Readme from '../../readmes/split-button/readme.md';
11-
import { LiveEditorCompact } from '@site/src/components/LiveEditorCompact';
126
import { ExampleLink } from '@site/src/components/ExampleLink';
7+
import SplitButtonPreview from '@site/src/components/previews/components/SplitButton';
138

149
# SplitButton
1510

@@ -24,11 +19,11 @@ dem sich weitere Aktionen verbergen.
2419

2520
## Konstruktion
2621

27-
### Code
28-
29-
```html
30-
<kol-split-button _label="Split-Button">Split-Button Popover</kol-split-button>
31-
```
22+
<SplitButtonPreview
23+
visibleProperties={['_label', '_variant', '_tooltipAlign', '_icons', '_disabled', '_hideLabel', '_slot']}
24+
codeCollapsable
25+
codeCollapsed
26+
/>
3227

3328
### Events
3429

@@ -41,14 +36,16 @@ Zur Behandlung von Events bzw. Callbacks siehe <kol-link _label="Events" _href="
4136

4237
### Beispiel
4338

44-
<kol-split-button _label="Split-Button">
45-
Split-Button Popover
46-
</kol-split-button>
39+
<SplitButtonPreview
40+
visibleProperties={[]}
41+
codeCollapsable
42+
codeCollapsed
43+
/>
4744

48-
<Readme />
45+
# API
4946

50-
<ExampleLink component="split-button" />
47+
<Readme />
5148

52-
## Live-Editor
49+
## Beispiele
5350

54-
<LiveEditorCompact component="split-button" />
51+
<ExampleLink component="split-button" />

i18n/de/code.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,12 @@
519519
"preview.component.image.label": {
520520
"message": "Beispielbild"
521521
},
522+
"preview.component.split-button.label": {
523+
"message": "Split-Button"
524+
},
525+
"preview.component.split-button.slot": {
526+
"message": "Popover-Inhalt"
527+
},
522528
"preview.property.remove": {
523529
"message": "Entfernen"
524530
},

i18n/en/code.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,12 @@
519519
"preview.component.image.label": {
520520
"message": "Sample image"
521521
},
522+
"preview.component.split-button.label": {
523+
"message": "Split Button"
524+
},
525+
"preview.component.split-button.slot": {
526+
"message": "Popover Content"
527+
},
522528
"preview.property.remove": {
523529
"message": "Remove"
524530
},

i18n/en/docusaurus-plugin-content-docs/current/30-components/split-button.mdx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ title: Split-Button
33
description: Description, specification and examples for the Split Button component.
44
---
55
import Readme from '/readmes/split-button/readme.md';
6-
import { LiveEditorCompact } from '@site/src/components/LiveEditorCompact';
76
import { ExampleLink } from '@site/src/components/ExampleLink';
7+
import SplitButtonPreview from '@site/src/components/previews/components/SplitButton';
88

99
# Split-Button
1010

@@ -19,11 +19,11 @@ which further actions are hidden.
1919

2020
## Construction
2121

22-
### Code
23-
24-
```html
25-
<kol-split-button _label="Split-Button">Split-Button Popover</kol-split-button>
26-
```
22+
<SplitButtonPreview
23+
visibleProperties={['_label', '_variant', '_tooltipAlign', '_icons', '_disabled', '_hideLabel', '_slot']}
24+
codeCollapsable
25+
codeCollapsed
26+
/>
2727

2828
### Events
2929

@@ -36,14 +36,16 @@ For the handling of events or callbacks, see <kol-link _label="Events" _href="..
3636

3737
### Example
3838

39-
<kol-split-button _label="Split-Button">
40-
Split button popover
41-
</kol-split-button>
39+
<SplitButtonPreview
40+
visibleProperties={[]}
41+
codeCollapsable
42+
codeCollapsed
43+
/>
4244

43-
<Readme />
45+
# API
4446

45-
<ExampleLink component="split-button" />
47+
<Readme />
4648

47-
## Live editor
49+
## Examples
4850

49-
<LiveEditorCompact component="split-button" />
51+
<ExampleLink component="split-button" />
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React from 'react';
2+
import Preview, { PreviewLayout } from '../Preview';
3+
import { BooleanProperty, AlignProperty, IconsProperty, ButtonVariantProperty, MultiLineTextProperty } from '../properties';
4+
import type { JSX } from '@public-ui/components';
5+
import { KolInputText, KolSplitButton } from '@public-ui/react-v19';
6+
import { translate } from '@docusaurus/Translate';
7+
import { sanitizeHtml } from '../../../shares/sanitize';
8+
9+
type SplitButtonPreviewProps = JSX.KolSplitButton & { _slot?: string };
10+
11+
interface SplitButtonPreviewComponentProps {
12+
initialProps?: SplitButtonPreviewProps;
13+
visibleProperties?: (keyof JSX.KolSplitButton | '_slot')[];
14+
codeCollapsable?: boolean;
15+
codeCollapsed?: boolean;
16+
}
17+
18+
const SplitButtonPreview: React.FC<SplitButtonPreviewComponentProps> = (props) => {
19+
const defaultProps = React.useMemo<SplitButtonPreviewProps>(
20+
() => ({
21+
_label: translate({ id: 'preview.component.split-button.label' }),
22+
_slot: translate({ id: 'preview.component.split-button.slot' }),
23+
}),
24+
[],
25+
);
26+
27+
return (
28+
<Preview<SplitButtonPreviewProps>
29+
propertyComponents={{
30+
_label: <KolInputText _label="Label" />,
31+
_variant: <ButtonVariantProperty label="Variant" defaultValue="normal" />,
32+
_tooltipAlign: <AlignProperty label="Tooltip Align" defaultValue="top" />,
33+
_icons: <IconsProperty label="Icons" />,
34+
_disabled: <BooleanProperty label="Disabled" />,
35+
_hideLabel: <BooleanProperty label="Hide Label" />,
36+
_slot: <MultiLineTextProperty label="Popover Content" />,
37+
}}
38+
initialProps={{ ...defaultProps, ...props.initialProps }}
39+
componentName="KolSplitButton"
40+
visibleProperties={props.visibleProperties}
41+
codeCollapsable={props.codeCollapsable}
42+
codeCollapsed={props.codeCollapsed}
43+
layout={PreviewLayout.CENTERED}
44+
slotKey="_slot"
45+
>
46+
{(componentProps) => {
47+
const { _slot, ...splitButtonProps } = componentProps;
48+
const sanitizedHtml = sanitizeHtml(_slot ?? '');
49+
return (
50+
<KolSplitButton {...splitButtonProps}>
51+
<div dangerouslySetInnerHTML={{ __html: sanitizedHtml }} />
52+
</KolSplitButton>
53+
);
54+
}}
55+
</Preview>
56+
);
57+
};
58+
59+
export default SplitButtonPreview;

0 commit comments

Comments
 (0)