Skip to content

Commit 3ca92f2

Browse files
committed
Improve SplitButton sample
Refs: #7805
1 parent f45cab4 commit 3ca92f2

File tree

1 file changed

+32
-18
lines changed
  • packages/samples/react/src/components/split-button

1 file changed

+32
-18
lines changed

packages/samples/react/src/components/split-button/basic.tsx

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
11
import React from 'react';
22

3-
import { ToasterService } from '@public-ui/components';
4-
import { KolSplitButton } from '@public-ui/react';
3+
import { KolSplitButton, KolToolbar, KolHeading } from '@public-ui/react';
54
import { SampleDescription } from '../SampleDescription';
5+
import { useToasterService } from '../../hooks/useToasterService';
66

77
import type { FC } from 'react';
88

99
export const SplitButtonBasic: FC = () => {
10-
const toaster = ToasterService.getInstance(document);
11-
const handleButtonClick = () => {
12-
void toaster.enqueue({
13-
description: 'The Button has been clicked.',
14-
label: `Button Clicked`,
15-
type: 'info',
16-
});
10+
const { buttonWithTextClickEventHandler } = useToasterService();
11+
const dummyEventHandler = {
12+
onClick: buttonWithTextClickEventHandler,
1713
};
14+
const TOOLBAR_ITEMS = [
15+
{
16+
_label: 'Save',
17+
_icons: 'codicon codicon-save',
18+
_on: dummyEventHandler,
19+
},
20+
{
21+
_label: 'Move',
22+
_icons: 'codicon codicon-move',
23+
_on: dummyEventHandler,
24+
},
25+
{
26+
_label: 'Delete',
27+
_icons: 'codicon codicon-trash',
28+
_on: dummyEventHandler,
29+
},
30+
];
1831

1932
return (
2033
<>
2134
<SampleDescription>
2235
<p>
23-
SplitButton renders a button with an additional context-menu, that can be opened by clicking the arrow icon. The first sample shows the button with an
24-
assigned action. In the second sample no action is assigned and clicking the button opens the context menu instead.
36+
The <code>SplitButton</code> component combines a primary action button with a context menu. Clicking the main button triggers the
37+
<strong> Edit</strong> action. The context menu opens a vertical list of additional actions:
38+
<strong> Save</strong>, <strong>Move</strong>, and <strong>Delete</strong>.
2539
</p>
2640
</SampleDescription>
2741

28-
<div className="flex gap-4">
29-
<KolSplitButton _label="Only the arrow opens" _on={{ onClick: handleButtonClick }}>
30-
Dropdown contents
31-
</KolSplitButton>
32-
<KolSplitButton _label="Button without visible label" _hideLabel _icons="codicon codicon-git-pull-request">
33-
Dropdown contents
34-
</KolSplitButton>
42+
<div className="flex flex-col gap-4">
43+
<KolHeading _label="SplitButton with vertical action list" _level={2} />
44+
<div className="flex gap-4">
45+
<KolSplitButton _label="Edit" _on={dummyEventHandler}>
46+
<KolToolbar _label="Action toolbar" _items={TOOLBAR_ITEMS} _orientation="vertical" />
47+
</KolSplitButton>
48+
</div>
3549
</div>
3650
</>
3751
);

0 commit comments

Comments
 (0)