@takaro/lib-components 0.0.14 → 0.0.18
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/Dockerfile.dev +1 -1
- package/package.json +23 -24
- package/src/components/actions/Button/Button.test.tsx +2 -1
- package/src/components/actions/Button/__snapshots__/Button.test.tsx.snap +18 -0
- package/src/components/actions/Button/style.ts +1 -0
- package/src/components/actions/DropdownButton/index.tsx +51 -36
- package/src/components/actions/IconButton/IconButton.test.tsx +3 -2
- package/src/components/actions/IconButton/__snapshots__/IconButton.test.tsx.snap +18 -0
- package/src/components/actions/IconButton/getIconSize.ts +16 -0
- package/src/components/actions/IconButton/index.tsx +2 -16
- package/src/components/actions/ToggleButton/ToggleButtonGroup.tsx +0 -1
- package/src/components/charts/AreaChart/AreaChart.stories.tsx +15 -20
- package/src/components/charts/GeoMercator/GeoMercator.stories.tsx +24 -18
- package/src/components/charts/GeoMercator/index.tsx +158 -56
- package/src/components/charts/GeoMercator/iso3166-alpha2-to-alpha3.ts +250 -0
- package/src/components/charts/GeoMercator/world.json +333 -0
- package/src/components/charts/RadialBarChart/index.tsx +1 -1
- package/src/components/charts/ZoomControls.tsx +47 -0
- package/src/components/charts/index.tsx +3 -0
- package/src/components/data/Chip/Chip.test.tsx +3 -2
- package/src/components/data/Chip/__snapshots__/Chip.test.tsx.snap +38 -0
- package/src/components/data/Console/Console.tsx +1 -7
- package/src/components/data/Console/ConsoleLine/index.tsx +1 -1
- package/src/components/data/Console/constants.ts +6 -0
- package/src/components/data/Table/index.tsx +31 -2
- package/src/components/data/Table/subcomponents/Filter/field.tsx +2 -3
- package/src/components/data/Table/subcomponents/Filter/index.tsx +1 -11
- package/src/components/data/Table/subcomponents/Filter/types.ts +10 -0
- package/src/components/data/Table/subcomponents/Pagination/PageSizeSelect.tsx +0 -1
- package/src/components/data/index.ts +0 -3
- package/src/components/dialogs/Dialog/DialogBody.tsx +1 -0
- package/src/components/dialogs/Dialog/DialogContent.tsx +1 -5
- package/src/components/feedback/Alert/Alert.stories.tsx +1 -10
- package/src/components/feedback/Alert/Alert.test.tsx +2 -1
- package/src/components/feedback/Alert/__snapshots__/Alert.test.tsx.snap +44 -0
- package/src/components/feedback/Alert/index.tsx +11 -15
- package/src/components/feedback/Alert/style.ts +9 -11
- package/src/components/feedback/ErrorPage/index.tsx +1 -1
- package/src/components/feedback/IconTooltip/IconTooltip.stories.tsx +22 -0
- package/src/components/feedback/IconTooltip/index.tsx +50 -0
- package/src/components/feedback/Loaders/Loading.test.tsx +2 -1
- package/src/components/feedback/Loaders/Spinner.test.tsx +2 -1
- package/src/components/feedback/Loaders/__snapshots__/Loading.test.tsx.snap +141 -0
- package/src/components/feedback/Loaders/__snapshots__/Spinner.test.tsx.snap +10 -0
- package/src/components/feedback/NetworkDetector/NetworkDetector.test.tsx +2 -1
- package/src/components/feedback/NetworkDetector/__snapshots__/NetworkDetector.test.tsx.snap +3 -0
- package/src/components/feedback/NotificationBanner/NotificationBanner.test.tsx +2 -1
- package/src/components/feedback/NotificationBanner/__snapshots__/NotificationBanner.test.tsx.snap +3 -0
- package/src/components/feedback/ProgressBar/ProgressBar.stories.tsx +2 -1
- package/src/components/feedback/ProgressBar/index.tsx +58 -24
- package/src/components/feedback/Skeleton/Skeleton.test.tsx +2 -1
- package/src/components/feedback/Skeleton/__snapshots__/Skeleton.test.tsx.snap +9 -0
- package/src/components/feedback/Tooltip/TooltipContent.tsx +2 -2
- package/src/components/feedback/Tooltip/useTooltip.tsx +3 -0
- package/src/components/feedback/index.ts +2 -1
- package/src/components/feedback/snacks/Drawer/Drawer.stories.tsx +1 -1
- package/src/components/feedback/snacks/Drawer/index.tsx +19 -4
- package/src/components/inputs/Date/DateRangePicker/Context.tsx +1 -1
- package/src/components/inputs/Date/DateRangePicker/Generic.tsx +2 -1
- package/src/components/inputs/Date/DateRangePicker/QuickSelect/index.tsx +1 -17
- package/src/components/inputs/Date/subcomponents/RelativePicker/index.tsx +1 -17
- package/src/components/inputs/Date/types.ts +14 -0
- package/src/components/inputs/DurationField/Generic.tsx +0 -1
- package/src/components/inputs/TextField/Controlled.tsx +1 -1
- package/src/components/inputs/TextField/Generic.tsx +79 -56
- package/src/components/inputs/TextField/TextField.stories.tsx +21 -1
- package/src/components/inputs/TextField/style.ts +6 -0
- package/src/components/inputs/TextField/util.ts +7 -2
- package/src/components/inputs/index.ts +1 -0
- package/src/components/inputs/layout/Description.tsx +0 -5
- package/src/components/inputs/layout/Label/style.ts +0 -1
- package/src/components/inputs/layout/index.ts +3 -1
- package/src/components/inputs/layout/setAriaDescribedBy.ts +3 -0
- package/src/components/inputs/selects/SelectField/Controlled.tsx +0 -2
- package/src/components/inputs/selects/SelectField/Generic/index.tsx +11 -14
- package/src/components/inputs/selects/SelectQueryField/Controlled.tsx +2 -2
- package/src/components/inputs/selects/SelectQueryField/Generic/index.tsx +134 -54
- package/src/components/inputs/selects/SelectQueryField/style.ts +0 -1
- package/src/components/inputs/selects/SubComponents/Option.tsx +1 -1
- package/src/components/inputs/selects/sharedStyle.ts +0 -2
- package/src/components/layout/Container/index.ts +1 -1
- package/src/components/layout/index.ts +1 -1
- package/src/components/navigation/HorizontalNav/HorizontalNav.stories.tsx +6 -22
- package/src/components/navigation/HorizontalNav/index.tsx +1 -1
- package/src/components/navigation/HorizontalNav/style.ts +28 -3
- package/src/components/navigation/Steppers/SlimStepper/Stepper.stories.tsx +2 -1
- package/src/components/navigation/Steppers/SlimStepper/index.tsx +4 -4
- package/src/components/navigation/Steppers/Stepper/Stepper.stories.tsx +2 -1
- package/src/components/navigation/Steppers/Stepper/index.tsx +4 -4
- package/src/components/navigation/Steppers/context.tsx +2 -49
- package/src/components/navigation/Steppers/provider.tsx +18 -0
- package/src/components/navigation/Steppers/useStepper.ts +34 -0
- package/src/components/navigation/index.ts +2 -1
- package/src/components/other/ActionMenu/index.tsx +20 -11
- package/src/components/other/ActionMenu/style.ts +2 -2
- package/src/components/other/ClipBoard/ClipBoard.test.tsx +2 -1
- package/src/components/other/ClipBoard/__snapshots__/ClipBoard.test.tsx.snap +36 -0
- package/src/components/other/Empty/Empty.test.tsx +5 -2
- package/src/components/other/Empty/__snapshots__/Empty.test.tsx.snap +21 -0
- package/src/components/other/PermissionsGuard/hasPermissionsHelper.ts +18 -0
- package/src/components/other/PermissionsGuard/index.tsx +1 -17
- package/src/components/other/Plan/Plan.stories.tsx +21 -0
- package/src/components/other/Plan/index.tsx +93 -0
- package/src/components/other/Plan/style.ts +61 -0
- package/src/components/other/Usage/Usage.stories.tsx +21 -0
- package/src/components/other/Usage/Usage.tsx +35 -0
- package/src/components/other/Usage/UsageCard.stories.tsx +31 -0
- package/src/components/other/Usage/UsageCard.tsx +88 -0
- package/src/components/other/index.ts +10 -2
- package/src/components/visual/Card/Card.stories.tsx +4 -1
- package/src/components/visual/Card/CardBody.tsx +11 -0
- package/src/components/visual/Card/CardTitle.tsx +23 -0
- package/src/components/visual/Card/index.tsx +19 -9
- package/src/components/visual/Divider/Divider.test.tsx +2 -1
- package/src/components/visual/Divider/__snapshots__/Divider.test.tsx.snap +13 -0
- package/src/components/visual/Divider/index.tsx +9 -6
- package/src/errors/errors.ts +1 -1
- package/src/helpers/regexprs.ts +2 -1
- package/tsconfig.json +0 -5
- package/vite.config.mts +17 -0
- package/src/components/data/LinkCard/index.tsx +0 -28
- package/src/components/feedback/QuestionTooltip/QuestionTooltip.stories.tsx +0 -20
- package/src/components/feedback/QuestionTooltip/index.tsx +0 -35
package/Dockerfile.dev
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takaro/lib-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Takaro UI is a simple and customizable component library to build React apps faster within the Takaro eco system",
|
|
6
6
|
"license": "AGPL-3.0-or-later",
|
|
@@ -9,10 +9,8 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "storybook build -c ../../.storybook",
|
|
11
11
|
"start:dev": "NODE_OPTIONS='' storybook dev -c ../../.storybook -p 13002",
|
|
12
|
-
"_test": "jest",
|
|
13
12
|
"test:unit": "CI=true vitest",
|
|
14
|
-
"test:
|
|
15
|
-
"test:update": "jest --updateSnapshot"
|
|
13
|
+
"test:snapshot": "vitest -u"
|
|
16
14
|
},
|
|
17
15
|
"devDependencies": {
|
|
18
16
|
"@hookform/devtools": "4.3.1",
|
|
@@ -31,16 +29,33 @@
|
|
|
31
29
|
"@rjsf/core": "5.20.0",
|
|
32
30
|
"@rjsf/utils": "5.20.0",
|
|
33
31
|
"@rjsf/validator-ajv8": "5.20.0",
|
|
32
|
+
"@sentry/react": "8.53.0",
|
|
34
33
|
"@tanstack/react-table": "8.20.5",
|
|
35
|
-
"@tanstack/react-router": "1.
|
|
34
|
+
"@tanstack/react-router": "1.102.1",
|
|
36
35
|
"@types/luxon": "3.4.2",
|
|
36
|
+
"@visx/axis": "3.10.1",
|
|
37
|
+
"@visx/brush": "3.10.4",
|
|
38
|
+
"@visx/curve": "3.3.0",
|
|
39
|
+
"@visx/event": "3.3.0",
|
|
40
|
+
"@visx/geo": "3.5.0",
|
|
41
|
+
"@visx/gradient": "3.3.0",
|
|
42
|
+
"@visx/grid": "3.5.0",
|
|
43
|
+
"@visx/group": "3.3.0",
|
|
44
|
+
"@visx/heatmap": "3.3.0",
|
|
45
|
+
"@visx/mock-data": "3.3.0",
|
|
46
|
+
"@visx/pattern": "3.3.0",
|
|
47
|
+
"@visx/responsive": "3.10.2",
|
|
48
|
+
"@visx/scale": "3.5.0",
|
|
49
|
+
"@visx/shape": "3.5.0",
|
|
50
|
+
"@visx/tooltip": "3.3.0",
|
|
51
|
+
"@visx/vendor": "3.5.0",
|
|
52
|
+
"@visx/zoom": "3.3.0",
|
|
37
53
|
"framer-motion": "11.9.0",
|
|
38
54
|
"luxon": "3.5.0",
|
|
39
55
|
"notistack": "3.0.1",
|
|
40
56
|
"polished": "4.3.1",
|
|
41
57
|
"react": "18.3.1",
|
|
42
58
|
"react-dnd": "16.0.1",
|
|
43
|
-
"@sentry/react": "8.32.0",
|
|
44
59
|
"react-dnd-html5-backend": "16.0.1",
|
|
45
60
|
"react-dom": "18.3.1",
|
|
46
61
|
"react-hook-form": "7.53.0",
|
|
@@ -50,23 +65,7 @@
|
|
|
50
65
|
"react-window": "1.8.10",
|
|
51
66
|
"simplebar-react": "3.2.6",
|
|
52
67
|
"styled-components": "5.3.11",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"@visx/responsive": "3.10.2",
|
|
56
|
-
"@visx/group": "3.3.0",
|
|
57
|
-
"@visx/heatmap": "3.3.0",
|
|
58
|
-
"@visx/tooltip": "3.3.0",
|
|
59
|
-
"@visx/event": "3.3.0",
|
|
60
|
-
"@visx/shape": "3.5.0",
|
|
61
|
-
"@visx/grid": "3.5.0",
|
|
62
|
-
"@visx/vendor": "3.5.0",
|
|
63
|
-
"@visx/brush": "3.10.4",
|
|
64
|
-
"@visx/axis": "3.10.1",
|
|
65
|
-
"@visx/pattern": "3.3.0",
|
|
66
|
-
"@visx/curve": "3.3.0",
|
|
67
|
-
"@visx/gradient": "3.3.0",
|
|
68
|
-
"@visx/mock-data": "3.3.0",
|
|
69
|
-
"@visx/geo": "3.5.0",
|
|
70
|
-
"topojson-client": "3.1.0"
|
|
68
|
+
"topojson-client": "3.1.0",
|
|
69
|
+
"web-vitals": "4.2.3"
|
|
71
70
|
}
|
|
72
71
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`Should render <Button/> 1`] = `
|
|
4
|
+
<div>
|
|
5
|
+
<button
|
|
6
|
+
class="sc-jlGgGc iqEzFy"
|
|
7
|
+
color="primary"
|
|
8
|
+
tabindex="0"
|
|
9
|
+
type="button"
|
|
10
|
+
>
|
|
11
|
+
|
|
12
|
+
<span>
|
|
13
|
+
button text
|
|
14
|
+
</span>
|
|
15
|
+
|
|
16
|
+
</button>
|
|
17
|
+
</div>
|
|
18
|
+
`;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useState, useEffect, ReactElement, useRef, forwardRef } from 'react';
|
|
2
2
|
import { useOutsideAlerter } from '../../../hooks';
|
|
3
3
|
import { MdChevronRight as ArrowIcon } from 'react-icons/md';
|
|
4
4
|
import { ActionMenu } from '../../../components';
|
|
5
5
|
import { styled } from '../../../styled';
|
|
6
|
-
import { useFloating } from '@floating-ui/react';
|
|
6
|
+
import { useFloating, useMergeRefs } from '@floating-ui/react';
|
|
7
|
+
import { shade } from 'polished';
|
|
8
|
+
import { ButtonColor } from '../Button/style';
|
|
7
9
|
|
|
8
10
|
const Arrow = styled(ArrowIcon)`
|
|
9
11
|
transform: rotate(90deg);
|
|
@@ -12,7 +14,7 @@ const Arrow = styled(ArrowIcon)`
|
|
|
12
14
|
|
|
13
15
|
const Wrapper = styled.div``;
|
|
14
16
|
|
|
15
|
-
const DropdownActionContainer = styled.div<{
|
|
17
|
+
const DropdownActionContainer = styled.div<{ color: ButtonColor }>`
|
|
16
18
|
font-weight: 500;
|
|
17
19
|
display: flex;
|
|
18
20
|
align-items: center;
|
|
@@ -20,94 +22,107 @@ const DropdownActionContainer = styled.div<{ isVisible: boolean }>`
|
|
|
20
22
|
justify-content: center;
|
|
21
23
|
cursor: pointer;
|
|
22
24
|
width: 3.2rem;
|
|
23
|
-
|
|
25
|
+
|
|
26
|
+
background: ${({ theme, color }) => shade(0.5, theme.colors[color])};
|
|
27
|
+
border: .1rem solid ${({ theme, color }) => theme.colors[color === 'background' ? 'backgroundAccent' : color]}};
|
|
24
28
|
border-top-right-radius: ${({ theme }) => theme.borderRadius.small}};
|
|
25
29
|
border-bottom-right-radius: ${({ theme }) => theme.borderRadius.small}};
|
|
26
|
-
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
svg {
|
|
31
|
-
fill: ${({ theme }) => theme.colors.primary};
|
|
32
|
-
}
|
|
31
|
+
svg {
|
|
32
|
+
fill: ${({ theme }) => theme.colors.text};
|
|
33
33
|
}
|
|
34
34
|
&:active {
|
|
35
35
|
background-color: transparent;
|
|
36
36
|
}
|
|
37
37
|
`;
|
|
38
38
|
|
|
39
|
-
const CurrentAction = styled.div
|
|
39
|
+
const CurrentAction = styled.div<{ color: ButtonColor }>`
|
|
40
40
|
padding: ${({ theme }) => `${theme.spacing['0_5']} ${theme.spacing[1]}`};
|
|
41
41
|
font-weight: 500;
|
|
42
42
|
cursor: pointer;
|
|
43
43
|
min-width: 10rem;
|
|
44
44
|
height: 100%;
|
|
45
45
|
color: ${({ theme }) => theme.colors.text};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
width: calc(100% - 3.2rem);
|
|
47
|
+
white-space: nowrap;
|
|
48
|
+
|
|
49
|
+
background: ${({ theme, color }) => shade(0.5, theme.colors[color])};
|
|
50
|
+
border-top: 0.1rem solid ${({ theme, color }) => theme.colors[color === 'background' ? 'backgroundAccent' : color]};
|
|
51
|
+
border-left: 0.1rem solid ${({ theme, color }) => theme.colors[color === 'background' ? 'backgroundAccent' : color]};
|
|
52
|
+
border-bottom: 0.1rem solid ${({ theme, color }) => theme.colors[color === 'background' ? 'backgroundAccent' : color]};
|
|
49
53
|
border-top-left-radius: ${({ theme }) => theme.borderRadius.small};
|
|
50
54
|
border-bottom-left-radius: ${({ theme }) => theme.borderRadius.small};
|
|
51
55
|
|
|
52
56
|
text-align: center;
|
|
53
|
-
&:hover {
|
|
54
|
-
color: ${({ theme }) => theme.colors.primary};
|
|
55
|
-
border-color: ${({ theme }) => theme.colors.primary};
|
|
56
|
-
}
|
|
57
57
|
&:active {
|
|
58
58
|
background-color: transparent;
|
|
59
59
|
}
|
|
60
60
|
`;
|
|
61
61
|
|
|
62
|
-
const Container = styled.div
|
|
62
|
+
const Container = styled.div<{ fullWidth: boolean }>`
|
|
63
63
|
display: flex;
|
|
64
64
|
align-items: center;
|
|
65
65
|
flex-wrap: wrap;
|
|
66
66
|
border-radius: ${({ theme }) => theme.borderRadius.large};
|
|
67
|
-
width: max-content;
|
|
68
|
-
|
|
69
|
-
&:hover ${DropdownActionContainer} {
|
|
70
|
-
border-left-color: ${({ theme }) => theme.colors.primary};
|
|
71
|
-
}
|
|
67
|
+
width: ${({ fullWidth }) => (fullWidth ? '100%' : 'max-content')};
|
|
72
68
|
`;
|
|
73
69
|
|
|
74
70
|
export interface DropdownButtonProps {
|
|
75
71
|
children: ReactElement[];
|
|
72
|
+
color?: ButtonColor;
|
|
73
|
+
onSelectedChanged?: (index: number) => void;
|
|
74
|
+
fullWidth?: boolean;
|
|
76
75
|
}
|
|
77
76
|
|
|
78
|
-
export const DropdownButton
|
|
79
|
-
|
|
77
|
+
export const DropdownButton = forwardRef<HTMLDivElement, DropdownButtonProps>(function Dropdown(
|
|
78
|
+
{ children, color = 'primary', onSelectedChanged, fullWidth = false },
|
|
79
|
+
propRef,
|
|
80
|
+
) {
|
|
81
|
+
const [listVisible, setListVisible] = useState<boolean>(false);
|
|
80
82
|
const [selected, setSelected] = useState<number>(0);
|
|
81
83
|
const { x, y, refs, strategy } = useFloating();
|
|
82
84
|
|
|
83
85
|
const parentRef = useRef<HTMLDivElement>(null);
|
|
86
|
+
const ref = useMergeRefs([propRef, parentRef]);
|
|
84
87
|
|
|
85
88
|
useOutsideAlerter(parentRef, () => {
|
|
86
|
-
|
|
89
|
+
setListVisible(false);
|
|
87
90
|
});
|
|
88
91
|
|
|
89
92
|
useEffect(() => {
|
|
90
|
-
|
|
93
|
+
if (onSelectedChanged) {
|
|
94
|
+
onSelectedChanged(selected);
|
|
95
|
+
}
|
|
96
|
+
setListVisible(false);
|
|
91
97
|
}, [selected]);
|
|
92
98
|
|
|
93
99
|
const handleSelectedActionClicked = () => {
|
|
94
|
-
|
|
100
|
+
setListVisible(false);
|
|
95
101
|
children[selected].props.onClick();
|
|
96
102
|
};
|
|
97
103
|
|
|
104
|
+
// TODO: this element does not handle the case where there are no children/actions
|
|
105
|
+
|
|
98
106
|
return (
|
|
99
|
-
<Wrapper ref={
|
|
100
|
-
<Container ref={refs.setReference}>
|
|
101
|
-
<CurrentAction onClick={handleSelectedActionClicked}>
|
|
102
|
-
|
|
107
|
+
<Wrapper ref={ref}>
|
|
108
|
+
<Container ref={refs.setReference} fullWidth={fullWidth}>
|
|
109
|
+
<CurrentAction color={color} onClick={handleSelectedActionClicked} role="button">
|
|
110
|
+
{children[selected].props.text}
|
|
111
|
+
</CurrentAction>
|
|
112
|
+
<DropdownActionContainer role="button" color={color} onClick={() => setListVisible(!listVisible)}>
|
|
103
113
|
<Arrow size={20} />
|
|
104
114
|
</DropdownActionContainer>
|
|
105
|
-
{
|
|
106
|
-
<ActionMenu
|
|
115
|
+
{listVisible && (
|
|
116
|
+
<ActionMenu
|
|
117
|
+
selected={selected}
|
|
118
|
+
setSelected={(s) => setSelected(s)}
|
|
119
|
+
attributes={{ x, y, strategy }}
|
|
120
|
+
ref={refs.setFloating}
|
|
121
|
+
>
|
|
107
122
|
{children}
|
|
108
123
|
</ActionMenu>
|
|
109
124
|
)}
|
|
110
125
|
</Container>
|
|
111
126
|
</Wrapper>
|
|
112
127
|
);
|
|
113
|
-
};
|
|
128
|
+
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { IconButton } from '.';
|
|
2
|
-
import { render } from 'test
|
|
2
|
+
import { render } from '../../../test/testUtils';
|
|
3
|
+
import { it, expect } from 'vitest';
|
|
3
4
|
|
|
4
5
|
it('Should render <IconButton />', () => {
|
|
5
|
-
const { container } = render(<IconButton icon={<div>icon</div>} />);
|
|
6
|
+
const { container } = render(<IconButton icon={<div>icon</div>} ariaLabel="test" />);
|
|
6
7
|
expect(container).toMatchSnapshot();
|
|
7
8
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`Should render <IconButton /> 1`] = `
|
|
4
|
+
<div>
|
|
5
|
+
<button
|
|
6
|
+
aria-label="test"
|
|
7
|
+
class="sc-lmUcrn bKlaHv"
|
|
8
|
+
color="primary"
|
|
9
|
+
type="button"
|
|
10
|
+
>
|
|
11
|
+
<div
|
|
12
|
+
size="18"
|
|
13
|
+
>
|
|
14
|
+
icon
|
|
15
|
+
</div>
|
|
16
|
+
</button>
|
|
17
|
+
</div>
|
|
18
|
+
`;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Size } from '../../../styled/types';
|
|
2
|
+
|
|
3
|
+
export const getIconSize = (size: Size) => {
|
|
4
|
+
switch (size) {
|
|
5
|
+
case 'tiny':
|
|
6
|
+
return 15;
|
|
7
|
+
case 'small':
|
|
8
|
+
return 16;
|
|
9
|
+
case 'medium':
|
|
10
|
+
return 18;
|
|
11
|
+
case 'large':
|
|
12
|
+
return 20;
|
|
13
|
+
case 'huge':
|
|
14
|
+
return 24;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -2,6 +2,7 @@ import { cloneElement, forwardRef, ReactElement } from 'react';
|
|
|
2
2
|
import { Color, Size } from '../../../styled/types';
|
|
3
3
|
import { Badge } from '../../../components';
|
|
4
4
|
import { Default } from './style';
|
|
5
|
+
import { getIconSize } from './getIconSize';
|
|
5
6
|
|
|
6
7
|
export interface IconButtonProps {
|
|
7
8
|
size?: Size;
|
|
@@ -14,28 +15,13 @@ export interface IconButtonProps {
|
|
|
14
15
|
badge?: string;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
const getSize = (size: Size) => {
|
|
18
|
-
switch (size) {
|
|
19
|
-
case 'tiny':
|
|
20
|
-
return 15;
|
|
21
|
-
case 'small':
|
|
22
|
-
return 16;
|
|
23
|
-
case 'medium':
|
|
24
|
-
return 18;
|
|
25
|
-
case 'large':
|
|
26
|
-
return 20;
|
|
27
|
-
case 'huge':
|
|
28
|
-
return 24;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
18
|
export const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(function IconButton(
|
|
33
19
|
{ icon, color = 'primary', size = 'medium', disabled, onClick = () => {}, ariaLabel, badge },
|
|
34
20
|
ref,
|
|
35
21
|
) {
|
|
36
22
|
return (
|
|
37
23
|
<Default type="button" color={color} onClick={onClick} ref={ref} disabled={disabled} aria-label={ariaLabel}>
|
|
38
|
-
{cloneElement(icon, { size:
|
|
24
|
+
{cloneElement(icon, { size: getIconSize(size) })}
|
|
39
25
|
{badge && <Badge>{badge}</Badge>}
|
|
40
26
|
</Default>
|
|
41
27
|
);
|
|
@@ -47,7 +47,6 @@ export const ToggleButtonGroup: FC<ToggleButtonGroupProps> & SubComponents = ({
|
|
|
47
47
|
const m = new Map<string, boolean>();
|
|
48
48
|
Children.forEach(children, (child) => {
|
|
49
49
|
if (isValidElement(child)) {
|
|
50
|
-
console.log(child.props.value, defaultValue);
|
|
51
50
|
if (child.props.value === defaultValue) {
|
|
52
51
|
m.set(child.props.value, true);
|
|
53
52
|
} else {
|
|
@@ -23,12 +23,6 @@ const Wrapper = styled.div`
|
|
|
23
23
|
width: 500px;
|
|
24
24
|
`;
|
|
25
25
|
|
|
26
|
-
const Header = styled.div`
|
|
27
|
-
display: flex;
|
|
28
|
-
align-items: center;
|
|
29
|
-
justify-content: space-between;
|
|
30
|
-
`;
|
|
31
|
-
|
|
32
26
|
export const Default: StoryFn<AreaChartProps<AppleStock>> = (args) => {
|
|
33
27
|
const getDate = (d: AppleStock) => new Date(d.date);
|
|
34
28
|
const getStockValue = (d: AppleStock) => d.close;
|
|
@@ -57,7 +51,7 @@ function generateData() {
|
|
|
57
51
|
const data: PingData[] = [];
|
|
58
52
|
for (let i = 0; i < 100; i++) {
|
|
59
53
|
const timestamp = faker.date.between({ from: '2021-01-01T00:00:00Z', to: '2021-01-31T23:59:59Z' }).toISOString();
|
|
60
|
-
const latency = faker.number.float({ min: 0, max: 70,
|
|
54
|
+
const latency = faker.number.float({ min: 0, max: 70, fractionDigits: 1 });
|
|
61
55
|
data.push({ timestamp, latency });
|
|
62
56
|
}
|
|
63
57
|
data.sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
|
|
@@ -75,8 +69,7 @@ export const PingExample: StoryFn = () => {
|
|
|
75
69
|
return (
|
|
76
70
|
<div style={{ width: 800, height: 300 }}>
|
|
77
71
|
<Card variant="outline">
|
|
78
|
-
<
|
|
79
|
-
<h2 style={{ marginBottom: '10px' }}>Ping latency</h2>
|
|
72
|
+
<Card.Title label="Ping latency">
|
|
80
73
|
<Dropdown>
|
|
81
74
|
<Dropdown.Trigger asChild>
|
|
82
75
|
<IconButton icon={<MenuIcon />} ariaLabel="open menu" />
|
|
@@ -87,17 +80,19 @@ export const PingExample: StoryFn = () => {
|
|
|
87
80
|
<Dropdown.Menu.Item onClick={() => {}} label="Option 3" />
|
|
88
81
|
</Dropdown.Menu>
|
|
89
82
|
</Dropdown>
|
|
90
|
-
</
|
|
91
|
-
<
|
|
92
|
-
<
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
83
|
+
</Card.Title>
|
|
84
|
+
<Card.Body>
|
|
85
|
+
<div style={{ height: '500px' }}>
|
|
86
|
+
<AreaChart<PingData>
|
|
87
|
+
name="Ping"
|
|
88
|
+
xAccessor={getDate}
|
|
89
|
+
yAccessor={getLatency}
|
|
90
|
+
tooltipAccessor={tooltipAccessor}
|
|
91
|
+
data={generateData()}
|
|
92
|
+
showBrush={false}
|
|
93
|
+
/>
|
|
94
|
+
</div>
|
|
95
|
+
</Card.Body>
|
|
101
96
|
</Card>
|
|
102
97
|
</div>
|
|
103
98
|
);
|
|
@@ -10,8 +10,7 @@ interface Shape {
|
|
|
10
10
|
name: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
const data: Shape[] = [
|
|
13
|
+
const alpha3: Shape[] = [
|
|
15
14
|
{ code: 'BEL', amount: 10, name: 'Belgium' },
|
|
16
15
|
{ code: 'CAN', amount: 20, name: 'Canada' },
|
|
17
16
|
{ code: 'DEU', amount: 30, name: 'Germany' },
|
|
@@ -27,19 +26,22 @@ const data: Shape[] = [
|
|
|
27
26
|
export default {
|
|
28
27
|
title: 'Charts/GeoMercator',
|
|
29
28
|
component: GeoMercator,
|
|
29
|
+
args: {
|
|
30
|
+
showZoomControls: false,
|
|
31
|
+
allowZoomAndDrag: false,
|
|
32
|
+
},
|
|
30
33
|
} as Meta<GeoMercatorProps<Shape>>;
|
|
31
34
|
|
|
32
35
|
const Wrapper = styled.div`
|
|
33
|
-
width:
|
|
34
|
-
height: 90vh;
|
|
36
|
+
width: fit-content;
|
|
35
37
|
`;
|
|
36
38
|
|
|
37
39
|
const Inner = styled.div`
|
|
38
|
-
width:
|
|
39
|
-
height:
|
|
40
|
+
width: 800px;
|
|
41
|
+
height: 800px;
|
|
40
42
|
`;
|
|
41
43
|
|
|
42
|
-
export const Default: StoryFn<GeoMercatorProps<Shape>> = () => {
|
|
44
|
+
export const Default: StoryFn<GeoMercatorProps<Shape>> = (args) => {
|
|
43
45
|
const getCountry = (d: Shape) => d.code;
|
|
44
46
|
const getAmount = (d: Shape) => Number(d.amount);
|
|
45
47
|
const tooltipAccessor = (d: Shape) => {
|
|
@@ -48,17 +50,21 @@ export const Default: StoryFn<GeoMercatorProps<Shape>> = () => {
|
|
|
48
50
|
|
|
49
51
|
return (
|
|
50
52
|
<Wrapper>
|
|
51
|
-
<Card
|
|
52
|
-
<
|
|
53
|
-
|
|
54
|
-
<
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
<Card>
|
|
54
|
+
<Card.Title label="Map" />
|
|
55
|
+
<Card.Body>
|
|
56
|
+
<Inner>
|
|
57
|
+
<GeoMercator<Shape>
|
|
58
|
+
name="geo-mercator"
|
|
59
|
+
xAccessor={getCountry}
|
|
60
|
+
yAccessor={getAmount}
|
|
61
|
+
tooltipAccessor={tooltipAccessor}
|
|
62
|
+
data={alpha3}
|
|
63
|
+
showZoomControls={args.showZoomControls}
|
|
64
|
+
allowZoomAndDrag={args.allowZoomAndDrag}
|
|
65
|
+
/>
|
|
66
|
+
</Inner>
|
|
67
|
+
</Card.Body>
|
|
62
68
|
</Card>
|
|
63
69
|
</Wrapper>
|
|
64
70
|
);
|