@takaro/lib-components 0.0.9 → 0.0.10
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 +4 -5
- package/src/components/inputs/index.ts +0 -4
- package/src/components/inputs/Slider/Controlled.tsx +0 -87
- package/src/components/inputs/Slider/Generic.tsx +0 -73
- package/src/components/inputs/Slider/Slider.stories.tsx +0 -101
- package/src/components/inputs/Slider/handle.tsx +0 -32
- package/src/components/inputs/Slider/index.tsx +0 -5
- package/src/components/inputs/Slider/style.ts +0 -140
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.10",
|
|
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",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@hookform/devtools": "^4.2.2",
|
|
19
19
|
"@mdx-js/react": "^2.1.5",
|
|
20
|
-
"@types/jest": "^
|
|
20
|
+
"@types/jest": "^29.0.0",
|
|
21
21
|
"@types/react-window": "^1.8.5",
|
|
22
22
|
"@types/styled-components": "^5.1.25",
|
|
23
23
|
"@types/topojson-client": "^3.1.4",
|
|
@@ -34,11 +34,10 @@
|
|
|
34
34
|
"@tanstack/react-table": "^8.7.9",
|
|
35
35
|
"@tanstack/react-router": "1.35.3",
|
|
36
36
|
"@types/luxon": "3.4.2",
|
|
37
|
-
"framer-motion": "^10.16.12",
|
|
37
|
+
"framer-motion": "^10.16.12 || ^11.0.0",
|
|
38
38
|
"luxon": "3.5.0",
|
|
39
39
|
"notistack": "^3.0.1",
|
|
40
40
|
"polished": "^4.1.3",
|
|
41
|
-
"rc-slider": "^9.7.5",
|
|
42
41
|
"react": "^18.2.0",
|
|
43
42
|
"react-dnd": "^16.0.1",
|
|
44
43
|
"@sentry/react": "^8.5.0",
|
|
@@ -51,7 +50,7 @@
|
|
|
51
50
|
"react-window": "^1.8.8",
|
|
52
51
|
"simplebar-react": "^3.2.4",
|
|
53
52
|
"styled-components": "^5.3.5",
|
|
54
|
-
"web-vitals": "^2.1.2",
|
|
53
|
+
"web-vitals": "^2.1.2 || ^4.0.0",
|
|
55
54
|
"@visx/scale": "^3.5.0",
|
|
56
55
|
"@visx/responsive": "^3.3.0",
|
|
57
56
|
"@visx/group": "^3.3.0",
|
|
@@ -26,10 +26,6 @@ export { ControlledTextAreaField as TextAreaField } from './TextAreaField';
|
|
|
26
26
|
export type { ControlledTextAreaFieldProps as TextAreaFieldProps } from './TextAreaField';
|
|
27
27
|
export { GenericTextAreaField as UnControlledTextAreaField } from './TextAreaField/Generic';
|
|
28
28
|
|
|
29
|
-
export { ControlledSlider as Slider } from './Slider';
|
|
30
|
-
export type { ControlledSliderProps as SliderProps } from './Slider';
|
|
31
|
-
export { GenericSlider as UnControlledSlider } from './Slider/Generic';
|
|
32
|
-
|
|
33
29
|
export { CodeField } from './CodeField';
|
|
34
30
|
export type { CodeFieldProps } from './CodeField';
|
|
35
31
|
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { FC, PropsWithChildren } from 'react';
|
|
2
|
-
import { useController } from 'react-hook-form';
|
|
3
|
-
import { ControlledInputProps, defaultInputProps, defaultInputPropsFactory } from '../InputProps';
|
|
4
|
-
import { SliderProps, GenericSlider } from '.';
|
|
5
|
-
import { Skeleton } from '../../../components';
|
|
6
|
-
import { Container } from './style';
|
|
7
|
-
import { InputWrapper, Description, ErrorMessage, Label } from '../layout';
|
|
8
|
-
|
|
9
|
-
export type ControlledSliderProps = ControlledInputProps & SliderProps;
|
|
10
|
-
|
|
11
|
-
const defaultsApplier = defaultInputPropsFactory<PropsWithChildren<ControlledSliderProps>>(defaultInputProps);
|
|
12
|
-
|
|
13
|
-
export const ControlledSlider: FC<ControlledSliderProps> = (props) => {
|
|
14
|
-
const {
|
|
15
|
-
name,
|
|
16
|
-
color = 'primary',
|
|
17
|
-
size,
|
|
18
|
-
min = 0,
|
|
19
|
-
max = 10,
|
|
20
|
-
step = 1,
|
|
21
|
-
required,
|
|
22
|
-
marks = [],
|
|
23
|
-
disabled,
|
|
24
|
-
loading,
|
|
25
|
-
label,
|
|
26
|
-
description,
|
|
27
|
-
hint,
|
|
28
|
-
control,
|
|
29
|
-
readOnly,
|
|
30
|
-
showTooltip = true,
|
|
31
|
-
showDots = false,
|
|
32
|
-
} = defaultsApplier(props);
|
|
33
|
-
|
|
34
|
-
const {
|
|
35
|
-
field,
|
|
36
|
-
fieldState: { error },
|
|
37
|
-
} = useController({
|
|
38
|
-
name,
|
|
39
|
-
control,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
if (loading) {
|
|
43
|
-
return <Skeleton height="6px" variant="text" width="100%" />;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return (
|
|
47
|
-
<InputWrapper>
|
|
48
|
-
<Container>
|
|
49
|
-
{label && (
|
|
50
|
-
<Label
|
|
51
|
-
position="top"
|
|
52
|
-
size={size}
|
|
53
|
-
text={label}
|
|
54
|
-
required={required}
|
|
55
|
-
error={!!error}
|
|
56
|
-
htmlFor={name}
|
|
57
|
-
hint={hint}
|
|
58
|
-
disabled={disabled}
|
|
59
|
-
/>
|
|
60
|
-
)}
|
|
61
|
-
<GenericSlider
|
|
62
|
-
disabled={disabled}
|
|
63
|
-
name={name}
|
|
64
|
-
id={name}
|
|
65
|
-
required={required}
|
|
66
|
-
min={min}
|
|
67
|
-
max={max}
|
|
68
|
-
size={size}
|
|
69
|
-
value={field.value}
|
|
70
|
-
marks={marks}
|
|
71
|
-
showDots={showDots}
|
|
72
|
-
hasError={!!error}
|
|
73
|
-
hasDescription={!!description}
|
|
74
|
-
step={step}
|
|
75
|
-
readOnly={readOnly}
|
|
76
|
-
showTooltip={showTooltip}
|
|
77
|
-
color={color}
|
|
78
|
-
onBlur={field.onBlur}
|
|
79
|
-
onChange={field.onChange}
|
|
80
|
-
ref={field.ref}
|
|
81
|
-
/>
|
|
82
|
-
{error && error.message && <ErrorMessage message={error.message} />}
|
|
83
|
-
</Container>
|
|
84
|
-
{description && <Description description={description} inputName={name} />}
|
|
85
|
-
</InputWrapper>
|
|
86
|
-
);
|
|
87
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { forwardRef } from 'react';
|
|
2
|
-
import { handle } from './handle';
|
|
3
|
-
import { Color } from '../../../styled';
|
|
4
|
-
import { StyledSlider } from './style';
|
|
5
|
-
import { defaultInputProps, defaultInputPropsFactory, GenericInputPropsFunctionHandlers } from '../InputProps';
|
|
6
|
-
|
|
7
|
-
interface Mark {
|
|
8
|
-
value: number;
|
|
9
|
-
label: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface SliderProps {
|
|
13
|
-
min: number;
|
|
14
|
-
max: number;
|
|
15
|
-
color?: Color;
|
|
16
|
-
showTooltip?: boolean;
|
|
17
|
-
marks?: Mark[];
|
|
18
|
-
step?: number;
|
|
19
|
-
showDots: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type GenericSliderProps = SliderProps & GenericInputPropsFunctionHandlers<number, HTMLDivElement>;
|
|
23
|
-
|
|
24
|
-
const defaultsApplier = defaultInputPropsFactory<GenericSliderProps>(defaultInputProps);
|
|
25
|
-
|
|
26
|
-
// TODO: should probably switch to the radixUI version
|
|
27
|
-
export const GenericSlider = forwardRef<HTMLDivElement, GenericSliderProps>(function GenericSlider(props, ref) {
|
|
28
|
-
const {
|
|
29
|
-
color = 'primary',
|
|
30
|
-
size,
|
|
31
|
-
min,
|
|
32
|
-
max,
|
|
33
|
-
step = 1,
|
|
34
|
-
value = max / 2,
|
|
35
|
-
marks = [],
|
|
36
|
-
readOnly,
|
|
37
|
-
showTooltip = true,
|
|
38
|
-
showDots,
|
|
39
|
-
onChange,
|
|
40
|
-
id,
|
|
41
|
-
} = defaultsApplier(props);
|
|
42
|
-
|
|
43
|
-
const handleOnChange = (value: number) => {
|
|
44
|
-
onChange(value);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// todo: memo this
|
|
48
|
-
const transformedMarks: { [key: number]: string } = {};
|
|
49
|
-
for (const { value, label } of marks) {
|
|
50
|
-
transformedMarks[value] = label;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<StyledSlider
|
|
55
|
-
id={id}
|
|
56
|
-
activeDotStyle={{ scale: 1.1 }}
|
|
57
|
-
color={color}
|
|
58
|
-
defaultValue={value as number}
|
|
59
|
-
disabled={readOnly}
|
|
60
|
-
dots={showDots}
|
|
61
|
-
handle={handle}
|
|
62
|
-
marks={transformedMarks}
|
|
63
|
-
max={max}
|
|
64
|
-
min={min}
|
|
65
|
-
onChange={handleOnChange}
|
|
66
|
-
ref={ref}
|
|
67
|
-
size={size}
|
|
68
|
-
step={step}
|
|
69
|
-
{...(showTooltip && { tipFormatter: undefined })}
|
|
70
|
-
tipProps={{ visible: showTooltip }}
|
|
71
|
-
/>
|
|
72
|
-
);
|
|
73
|
-
});
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
-
import { styled } from '../../../styled';
|
|
4
|
-
import { useForm, useWatch } from 'react-hook-form';
|
|
5
|
-
import { SliderProps, Slider } from '../../../components';
|
|
6
|
-
|
|
7
|
-
const Wrapper = styled.div`
|
|
8
|
-
display: flex;
|
|
9
|
-
align-items: center;
|
|
10
|
-
justify-content: center;
|
|
11
|
-
width: 100%;
|
|
12
|
-
height: 50vh;
|
|
13
|
-
padding: 2rem;
|
|
14
|
-
background: ${({ theme }) => theme.colors.background};
|
|
15
|
-
border-radius: ${({ theme }) => theme.borderRadius.large};
|
|
16
|
-
`;
|
|
17
|
-
|
|
18
|
-
export default {
|
|
19
|
-
title: 'Inputs/Slider',
|
|
20
|
-
component: Slider,
|
|
21
|
-
decorators: [(story) => <Wrapper>{story()}</Wrapper>],
|
|
22
|
-
args: {
|
|
23
|
-
readOnly: false,
|
|
24
|
-
description: 'Slider description',
|
|
25
|
-
min: 0,
|
|
26
|
-
max: 100,
|
|
27
|
-
hint: 'This is the hint',
|
|
28
|
-
name: 'Slider',
|
|
29
|
-
step: 1,
|
|
30
|
-
showTooltip: true,
|
|
31
|
-
label: 'Slider label',
|
|
32
|
-
disabled: false,
|
|
33
|
-
loading: false,
|
|
34
|
-
required: false,
|
|
35
|
-
},
|
|
36
|
-
} as Meta<SliderProps>;
|
|
37
|
-
|
|
38
|
-
const Template: StoryFn<SliderProps> = (args) => {
|
|
39
|
-
const { control } = useForm();
|
|
40
|
-
return <Slider {...args} control={control} />;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// Default Checkbox
|
|
44
|
-
export const Default = Template.bind({});
|
|
45
|
-
Default.args = {
|
|
46
|
-
name: 'default-slider',
|
|
47
|
-
min: 0,
|
|
48
|
-
max: 100,
|
|
49
|
-
step: 1,
|
|
50
|
-
loading: false,
|
|
51
|
-
label: 'slider label',
|
|
52
|
-
color: 'primary',
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const Steps = Template.bind({});
|
|
56
|
-
Steps.args = {
|
|
57
|
-
name: 'slider-with-steps',
|
|
58
|
-
min: 0,
|
|
59
|
-
max: 100,
|
|
60
|
-
step: 10,
|
|
61
|
-
showDots: false,
|
|
62
|
-
loading: false,
|
|
63
|
-
color: 'primary',
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export const StepsWithDots = Template.bind({});
|
|
67
|
-
StepsWithDots.args = {
|
|
68
|
-
name: 'slider-with-dots',
|
|
69
|
-
min: 0,
|
|
70
|
-
max: 100,
|
|
71
|
-
step: 10,
|
|
72
|
-
showDots: true,
|
|
73
|
-
loading: false,
|
|
74
|
-
color: 'primary',
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export const OnChange: StoryFn<SliderProps> = (args) => {
|
|
78
|
-
const { control } = useForm({ mode: 'onChange' });
|
|
79
|
-
const sliderValue = useWatch({ control, name: 'Slider' });
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
<>
|
|
83
|
-
<Slider
|
|
84
|
-
control={control}
|
|
85
|
-
description="slider description"
|
|
86
|
-
readOnly={args.readOnly}
|
|
87
|
-
label={args.label}
|
|
88
|
-
loading={args.loading}
|
|
89
|
-
showTooltip={args.showTooltip}
|
|
90
|
-
showDots={args.showDots}
|
|
91
|
-
max={args.max}
|
|
92
|
-
min={args.min}
|
|
93
|
-
name={args.name}
|
|
94
|
-
step={args.step}
|
|
95
|
-
required={args.required}
|
|
96
|
-
disabled={args.disabled}
|
|
97
|
-
/>
|
|
98
|
-
<pre>value: {sliderValue}</pre>
|
|
99
|
-
</>
|
|
100
|
-
);
|
|
101
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import Slider, { SliderTooltip } from 'rc-slider';
|
|
2
|
-
import { FC } from 'react';
|
|
3
|
-
|
|
4
|
-
const { Handle } = Slider;
|
|
5
|
-
|
|
6
|
-
interface handleParams {
|
|
7
|
-
className: string;
|
|
8
|
-
prefixCls?: string;
|
|
9
|
-
vertical?: boolean;
|
|
10
|
-
offset: number;
|
|
11
|
-
value: number;
|
|
12
|
-
dragging?: boolean;
|
|
13
|
-
disabled?: boolean;
|
|
14
|
-
min?: number;
|
|
15
|
-
max?: number;
|
|
16
|
-
reverse?: boolean;
|
|
17
|
-
index: number;
|
|
18
|
-
tabIndex?: number;
|
|
19
|
-
ariaLabel: string;
|
|
20
|
-
ariaLabelledBy: string;
|
|
21
|
-
ariaValueTextFormatter?: (value: number) => string;
|
|
22
|
-
style?: React.CSSProperties;
|
|
23
|
-
ref?: React.Ref<any>;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const handle: FC<handleParams> = ({ value, dragging, index, ...restProps }) => {
|
|
27
|
-
return (
|
|
28
|
-
<SliderTooltip key={index} overlay={`${value}`} placement="top" prefixCls="rc-slider-tooltip" visible={dragging}>
|
|
29
|
-
<Handle value={value} {...restProps} />
|
|
30
|
-
</SliderTooltip>
|
|
31
|
-
);
|
|
32
|
-
};
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { Color, Size, styled } from '../../../styled';
|
|
2
|
-
import Slider from 'rc-slider';
|
|
3
|
-
|
|
4
|
-
const createSliderWithTooltip = Slider.createSliderWithTooltip;
|
|
5
|
-
const SliderComp = createSliderWithTooltip(Slider);
|
|
6
|
-
|
|
7
|
-
export const Container = styled.div`
|
|
8
|
-
width: 100%;
|
|
9
|
-
`;
|
|
10
|
-
|
|
11
|
-
export const StyledSlider = styled<any | { color: Color; size: Size }>(SliderComp)`
|
|
12
|
-
|
|
13
|
-
.rc-slider-track {
|
|
14
|
-
background-color: ${({ theme, color }): string => theme.colors[color]};
|
|
15
|
-
${({ size }) => {
|
|
16
|
-
switch (size) {
|
|
17
|
-
case 'tiny':
|
|
18
|
-
return 'height: .3rem;';
|
|
19
|
-
case 'small':
|
|
20
|
-
return 'height: .4rem;';
|
|
21
|
-
case 'medium':
|
|
22
|
-
return 'height: .5rem;';
|
|
23
|
-
case 'large':
|
|
24
|
-
return 'height: .6rem;';
|
|
25
|
-
case 'huge':
|
|
26
|
-
return 'height: .9rem;';
|
|
27
|
-
}
|
|
28
|
-
}}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
.rc-slider-handle {
|
|
32
|
-
border: none;
|
|
33
|
-
position: relative;
|
|
34
|
-
background-color: ${({ theme, color }) => theme.colors[color]};
|
|
35
|
-
&::after {
|
|
36
|
-
content: '';
|
|
37
|
-
position: absolute;
|
|
38
|
-
left: 37.5%;
|
|
39
|
-
top: 50%;
|
|
40
|
-
transform: translateY(-50%);
|
|
41
|
-
height: 25%;
|
|
42
|
-
width: 25%;
|
|
43
|
-
border-radius: 100%;
|
|
44
|
-
background-color: ${({ theme }) => theme.colors.white} ;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
${({ size, theme }) => {
|
|
48
|
-
switch (size) {
|
|
49
|
-
case 'tiny':
|
|
50
|
-
return `
|
|
51
|
-
width: 1.2rem;
|
|
52
|
-
height : 1.2rem;
|
|
53
|
-
margin-top: -${theme.spacing['0_5']};
|
|
54
|
-
`;
|
|
55
|
-
case 'small':
|
|
56
|
-
return `
|
|
57
|
-
width: 1.4rem;
|
|
58
|
-
height : 1.4rem;
|
|
59
|
-
margin-top: -${theme.spacing['0_5']};
|
|
60
|
-
`;
|
|
61
|
-
case 'medium':
|
|
62
|
-
return `
|
|
63
|
-
width: 2rem;
|
|
64
|
-
height: 2rem;
|
|
65
|
-
margin-top: -${theme.spacing['0_75']};
|
|
66
|
-
`;
|
|
67
|
-
case 'large':
|
|
68
|
-
return `
|
|
69
|
-
width: 2.8rem;
|
|
70
|
-
height: 2.8rem;
|
|
71
|
-
margin-top: -${theme.spacing[1]};
|
|
72
|
-
`;
|
|
73
|
-
case 'huge':
|
|
74
|
-
return `
|
|
75
|
-
width: 2.8rem;
|
|
76
|
-
height: 2.8rem;
|
|
77
|
-
margin-left: -${theme.spacing['0_1']};
|
|
78
|
-
margin-top: -${theme.spacing[1]};
|
|
79
|
-
`;
|
|
80
|
-
}
|
|
81
|
-
}}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
.rc-slider-tooltip-inner {
|
|
86
|
-
background-color: ${({ theme, color }) => theme.colors[color]}!important;
|
|
87
|
-
box-shadow: ${({ theme }) => theme.elevation[2]};
|
|
88
|
-
font-weight: 600;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
.rc-slider-tooltip-arrow {
|
|
92
|
-
border-top-color: ${({ theme, color }) => theme.colors[color]}!important;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
.rc-slider-dot {
|
|
97
|
-
background-color: ${({ theme }): string => theme.colors.primary};
|
|
98
|
-
border-color: ${({ theme }): string => theme.colors.primary};
|
|
99
|
-
|
|
100
|
-
${({ size }) => {
|
|
101
|
-
switch (size) {
|
|
102
|
-
case 'tiny':
|
|
103
|
-
return `
|
|
104
|
-
width: 0.6rem;
|
|
105
|
-
height : 0.6rem;
|
|
106
|
-
top: -0.1rem;
|
|
107
|
-
`;
|
|
108
|
-
case 'small':
|
|
109
|
-
return `
|
|
110
|
-
width: 0.8rem;
|
|
111
|
-
height : 0.8rem;
|
|
112
|
-
top: -.2rem;
|
|
113
|
-
`;
|
|
114
|
-
case 'medium':
|
|
115
|
-
return `
|
|
116
|
-
width: 1.1rem;
|
|
117
|
-
height: 1.1rem;
|
|
118
|
-
top: -0.3rem;
|
|
119
|
-
`;
|
|
120
|
-
case 'large':
|
|
121
|
-
return `
|
|
122
|
-
width: 1.5rem;
|
|
123
|
-
height: 1.5rem;
|
|
124
|
-
top: -0.4rem;
|
|
125
|
-
`;
|
|
126
|
-
case 'huge':
|
|
127
|
-
return `
|
|
128
|
-
width: 1.8rem;
|
|
129
|
-
height: 1.8rem;
|
|
130
|
-
top: -0.5rem;
|
|
131
|
-
`;
|
|
132
|
-
}
|
|
133
|
-
}}
|
|
134
|
-
|
|
135
|
-
&.rc-slider-dot-active {
|
|
136
|
-
border: none;
|
|
137
|
-
background-color: ${({ theme, color }): string => theme.colors[color]};
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
`;
|