@arbor-education/design-system.components 0.25.1 → 0.25.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/components/row/Row.d.ts +5 -4
- package/dist/components/row/Row.d.ts.map +1 -1
- package/dist/components/row/Row.js +4 -2
- package/dist/components/row/Row.js.map +1 -1
- package/dist/components/row/Row.stories.d.ts +114 -4
- package/dist/components/row/Row.stories.d.ts.map +1 -1
- package/dist/components/row/Row.stories.js +451 -63
- package/dist/components/row/Row.stories.js.map +1 -1
- package/dist/components/row/Row.test.js +39 -0
- package/dist/components/row/Row.test.js.map +1 -1
- package/dist/components/toggleGroup/ToggleGroup.d.ts +29 -0
- package/dist/components/toggleGroup/ToggleGroup.d.ts.map +1 -0
- package/dist/components/toggleGroup/ToggleGroup.js +26 -0
- package/dist/components/toggleGroup/ToggleGroup.js.map +1 -0
- package/dist/components/toggleGroup/ToggleGroup.stories.d.ts +86 -0
- package/dist/components/toggleGroup/ToggleGroup.stories.d.ts.map +1 -0
- package/dist/components/toggleGroup/ToggleGroup.stories.js +342 -0
- package/dist/components/toggleGroup/ToggleGroup.stories.js.map +1 -0
- package/dist/components/toggleGroup/ToggleGroup.test.d.ts +2 -0
- package/dist/components/toggleGroup/ToggleGroup.test.d.ts.map +1 -0
- package/dist/components/toggleGroup/ToggleGroup.test.js +123 -0
- package/dist/components/toggleGroup/ToggleGroup.test.js.map +1 -0
- package/dist/components/toggleGroup/ToggleGroupItem.d.ts +10 -0
- package/dist/components/toggleGroup/ToggleGroupItem.d.ts.map +1 -0
- package/dist/components/toggleGroup/ToggleGroupItem.js +5 -0
- package/dist/components/toggleGroup/ToggleGroupItem.js.map +1 -0
- package/dist/index.css +33 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/row/Row.stories.tsx +638 -80
- package/src/components/row/Row.test.tsx +48 -0
- package/src/components/row/Row.tsx +15 -5
- package/src/components/toggleGroup/ToggleGroup.stories.tsx +429 -0
- package/src/components/toggleGroup/ToggleGroup.test.tsx +155 -0
- package/src/components/toggleGroup/ToggleGroup.tsx +74 -0
- package/src/components/toggleGroup/ToggleGroupItem.tsx +24 -0
- package/src/components/toggleGroup/toggleGroup.scss +43 -0
- package/src/index.scss +1 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useState, type KeyboardEventHandler } from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { ToggleGroup as RadixToggleGroup, type ToggleGroupSingleProps } from '@radix-ui/react-toggle-group';
|
|
4
|
+
import { ToggleGroupItem, type ToggleGroupItemProps, type ToggleGroupItemColor } from './ToggleGroupItem.js';
|
|
5
|
+
|
|
6
|
+
type ControlledProps = {
|
|
7
|
+
value: string;
|
|
8
|
+
onValueChange: (value: string) => void;
|
|
9
|
+
defaultValue?: never;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type UncontrolledProps = {
|
|
13
|
+
defaultValue?: string;
|
|
14
|
+
value?: never;
|
|
15
|
+
onValueChange?: never;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type BaseProps = Omit<ToggleGroupSingleProps, 'type' | 'value' | 'onValueChange' | 'defaultValue'> & {
|
|
19
|
+
options: ToggleGroupItemProps[];
|
|
20
|
+
onKeyDown?: KeyboardEventHandler<HTMLDivElement>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type ToggleGroupProps = BaseProps & (ControlledProps | UncontrolledProps);
|
|
24
|
+
|
|
25
|
+
const isControlled = (props: ToggleGroupProps): props is ControlledProps & ToggleGroupProps =>
|
|
26
|
+
props.value !== undefined;
|
|
27
|
+
|
|
28
|
+
export const ToggleGroup = (props: ToggleGroupProps) => {
|
|
29
|
+
const { options, className, value, defaultValue, onValueChange, onKeyDown, ...radixToggleGroupProps } = props;
|
|
30
|
+
const [internalValue, setInternalValue] = useState<string | undefined>(
|
|
31
|
+
isControlled(props) ? undefined : defaultValue,
|
|
32
|
+
);
|
|
33
|
+
const selectedValue = isControlled(props) ? value : internalValue;
|
|
34
|
+
|
|
35
|
+
const handleValueChange = (newValue: string) => {
|
|
36
|
+
if (!newValue) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (isControlled(props)) {
|
|
40
|
+
onValueChange?.(newValue);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
setInternalValue(newValue);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<RadixToggleGroup
|
|
49
|
+
{...radixToggleGroupProps}
|
|
50
|
+
type="single"
|
|
51
|
+
rovingFocus={false}
|
|
52
|
+
className={classNames('ds-toggle-group', className)}
|
|
53
|
+
value={selectedValue}
|
|
54
|
+
onValueChange={handleValueChange}
|
|
55
|
+
onKeyDown={onKeyDown}
|
|
56
|
+
>
|
|
57
|
+
{options.map(({ ...itemProps }) => (
|
|
58
|
+
<ToggleGroupItem
|
|
59
|
+
{...itemProps}
|
|
60
|
+
key={itemProps.value}
|
|
61
|
+
isActive={itemProps.value === selectedValue}
|
|
62
|
+
/>
|
|
63
|
+
))}
|
|
64
|
+
</RadixToggleGroup>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
ToggleGroup.Item = ToggleGroupItem;
|
|
69
|
+
|
|
70
|
+
export namespace ToggleGroup {
|
|
71
|
+
export type Props = ToggleGroupProps;
|
|
72
|
+
export type ItemProps = ToggleGroupItemProps;
|
|
73
|
+
export type ItemColor = ToggleGroupItemColor;
|
|
74
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Item, type ToggleGroupItemProps as RadixToggleGroupItemProps } from '@radix-ui/react-toggle-group';
|
|
2
|
+
import { Button } from 'Components/button/Button';
|
|
3
|
+
|
|
4
|
+
export type ToggleGroupItemColor = 'red' | 'yellow' | 'green';
|
|
5
|
+
|
|
6
|
+
export type ToggleGroupItemProps = {
|
|
7
|
+
text: string;
|
|
8
|
+
color?: ToggleGroupItemColor;
|
|
9
|
+
icon?: React.ReactNode;
|
|
10
|
+
isActive?: boolean;
|
|
11
|
+
} & RadixToggleGroupItemProps;
|
|
12
|
+
|
|
13
|
+
export const ToggleGroupItem = ({ text, color, icon, isActive = false, ...radixProps }: ToggleGroupItemProps) => (
|
|
14
|
+
<Item {...radixProps} asChild>
|
|
15
|
+
<Button
|
|
16
|
+
className={isActive && color ? `ds-toggle-group__item--${color}` : undefined}
|
|
17
|
+
borderless
|
|
18
|
+
variant={isActive ? 'primary' : 'secondary'}
|
|
19
|
+
>
|
|
20
|
+
{icon}
|
|
21
|
+
{text}
|
|
22
|
+
</Button>
|
|
23
|
+
</Item>
|
|
24
|
+
);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
.ds-toggle-group {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
border-radius: var(--border-radius-round);
|
|
4
|
+
border: var(--toggle-weight-border) solid var(--color-grey-100);
|
|
5
|
+
padding: var(--border-radius-small);
|
|
6
|
+
gap: 8px;
|
|
7
|
+
align-items: center;
|
|
8
|
+
|
|
9
|
+
.ds-toggle-group__item {
|
|
10
|
+
&--red {
|
|
11
|
+
background-color: var(--color-semantic-destructive-100);
|
|
12
|
+
color: var(--color-semantic-destructive-700);
|
|
13
|
+
|
|
14
|
+
&:focus,
|
|
15
|
+
&:hover {
|
|
16
|
+
background-color: var(--color-semantic-destructive-100);
|
|
17
|
+
color: var(--color-semantic-destructive-700);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&--yellow {
|
|
22
|
+
background-color: var(--color-semantic-caution-100);
|
|
23
|
+
color: var(--color-semantic-caution-700);
|
|
24
|
+
|
|
25
|
+
&:focus,
|
|
26
|
+
&:hover {
|
|
27
|
+
background-color: var(--color-semantic-caution-100);
|
|
28
|
+
color: var(--color-semantic-caution-700);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&--green {
|
|
33
|
+
background-color: var(--color-semantic-success-100);
|
|
34
|
+
color: var(--color-semantic-success-700);
|
|
35
|
+
|
|
36
|
+
&:focus,
|
|
37
|
+
&:hover {
|
|
38
|
+
background-color: var(--color-semantic-success-100);
|
|
39
|
+
color: var(--color-semantic-success-700);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/index.scss
CHANGED
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
@use "components/row/row.scss";
|
|
54
54
|
@use "components/combobox/combobox.scss";
|
|
55
55
|
@use "components/toggle/toggle.scss";
|
|
56
|
+
@use "components/toggleGroup/toggleGroup.scss";
|
|
56
57
|
@use "components/dataViewCard/dataViewCard.scss";
|
|
57
58
|
@use "components/treeRow/treeRow.scss";
|
|
58
59
|
@use "components/sidebarNav/sidebarNav.scss";
|
package/src/index.ts
CHANGED
|
@@ -74,6 +74,7 @@ export { TagList } from 'Components/tagList/TagList';
|
|
|
74
74
|
export type { TagListItem, TagListOverflowRenderArgs, TagListOverflowTarget, TagListProps } from 'Components/tagList/TagList';
|
|
75
75
|
export { Toast } from 'Components/toast/Toast';
|
|
76
76
|
export { Toggle } from 'Components/toggle/Toggle';
|
|
77
|
+
export { ToggleGroup } from 'Components/toggleGroup/ToggleGroup';
|
|
77
78
|
export { Tooltip } from 'Components/tooltip/Tooltip';
|
|
78
79
|
export { TooltipWrapper } from 'Components/tooltip/TooltipWrapper';
|
|
79
80
|
export { GovhubLogo, KeyLogo, RobinLogo, SampeopleLogo, TimetablerLogo } from 'Components/userDropdown/assets/logos';
|