@takaro/lib-components 0.0.9 → 0.0.11
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/data/Table/index.tsx +13 -1
- package/src/components/data/Table/react-table.d.ts +4 -1
- package/src/components/data/Table/subcomponents/ColumnVisibility/index.tsx +10 -1
- package/src/components/feedback/Alert/index.tsx +22 -21
- package/src/components/feedback/Alert/style.ts +9 -3
- package/src/components/inputs/index.ts +0 -4
- package/src/components/other/Collapsible/CollapsibleContent.tsx +7 -0
- package/src/components/other/Collapsible/CollapsibleTrigger.tsx +12 -0
- 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.11",
|
|
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",
|
|
@@ -93,7 +93,19 @@ export function Table<DataType extends object>({
|
|
|
93
93
|
if (column.id === undefined) {
|
|
94
94
|
throw new Error('ColumnDef must have an id');
|
|
95
95
|
}
|
|
96
|
-
|
|
96
|
+
|
|
97
|
+
if (column?.meta?.includeColumn == false) {
|
|
98
|
+
acc[column.id] = false;
|
|
99
|
+
return acc;
|
|
100
|
+
} else {
|
|
101
|
+
acc[column.id] = true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (column?.meta?.hideColumn) {
|
|
105
|
+
acc[column.id] = !column.meta.hideColumn;
|
|
106
|
+
} else {
|
|
107
|
+
acc[column.id] = true;
|
|
108
|
+
}
|
|
97
109
|
return acc;
|
|
98
110
|
},
|
|
99
111
|
{} as Record<string, boolean>,
|
|
@@ -5,7 +5,10 @@ type DataTypes = 'datetime' | 'number' | 'string' | 'boolean' | 'uuid';
|
|
|
5
5
|
|
|
6
6
|
declare module '@tanstack/table-core' {
|
|
7
7
|
interface ColumnMeta<TData extends RowData, TValue> {
|
|
8
|
-
|
|
8
|
+
/// Column is not visible in table by default, but can be enabled with view options
|
|
9
|
+
hideColumn?: boolean;
|
|
10
|
+
canShowColumn?: boolean;
|
|
11
|
+
includeColumn?: boolean;
|
|
9
12
|
dataType?: DataTypes;
|
|
10
13
|
}
|
|
11
14
|
}
|
|
@@ -18,7 +18,16 @@ export function ColumnVisibility<DataType extends object>({
|
|
|
18
18
|
openColumnVisibilityTooltip,
|
|
19
19
|
setHasShownColumnVisibilityTooltip,
|
|
20
20
|
}: ColumnVisibilityProps<DataType>) {
|
|
21
|
-
const viableColumns = table
|
|
21
|
+
const viableColumns = table
|
|
22
|
+
.getAllLeafColumns()
|
|
23
|
+
.filter((column) => column.getCanHide() === true)
|
|
24
|
+
.filter((column) => {
|
|
25
|
+
if (column.columnDef.meta?.includeColumn === false) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
});
|
|
30
|
+
|
|
22
31
|
const hiddenColumns = viableColumns.filter((column) => column.getIsVisible() === false);
|
|
23
32
|
|
|
24
33
|
return (
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forwardRef, MouseEvent, useState } from 'react';
|
|
1
|
+
import { forwardRef, isValidElement, MouseEvent, ReactElement, useState } from 'react';
|
|
2
2
|
import { Container, Grid, IconContainer, ButtonContainer } from './style';
|
|
3
3
|
import {
|
|
4
4
|
AiFillCheckCircle as Success,
|
|
@@ -20,14 +20,15 @@ type Action = {
|
|
|
20
20
|
export interface AlertProps {
|
|
21
21
|
variant: AlertVariants;
|
|
22
22
|
title?: string;
|
|
23
|
-
text?: string | string[];
|
|
23
|
+
text?: string | string[] | ReactElement;
|
|
24
24
|
elevation?: Elevation;
|
|
25
25
|
dismiss?: boolean;
|
|
26
26
|
action?: Action;
|
|
27
|
+
showIcon?: boolean;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(
|
|
30
|
-
{ variant, title, text, dismiss = false, elevation = 4, action },
|
|
31
|
+
{ variant, title, text, dismiss = false, elevation = 4, action, showIcon = true },
|
|
31
32
|
ref,
|
|
32
33
|
) {
|
|
33
34
|
const [visible, setVisible] = useState(true);
|
|
@@ -39,7 +40,6 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(
|
|
|
39
40
|
e.stopPropagation();
|
|
40
41
|
action?.execute();
|
|
41
42
|
};
|
|
42
|
-
|
|
43
43
|
const handleDismiss = (e: MouseEvent<HTMLButtonElement>) => {
|
|
44
44
|
e.preventDefault();
|
|
45
45
|
e.stopPropagation();
|
|
@@ -58,6 +58,19 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(
|
|
|
58
58
|
return <Info size={24} />;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
|
|
62
|
+
function renderText() {
|
|
63
|
+
if (isValidElement(text)) {
|
|
64
|
+
return text;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (typeof text === 'string') {
|
|
68
|
+
return <p>{text}</p>;
|
|
69
|
+
} else if (Array.isArray(text)) {
|
|
70
|
+
return <ul>{text?.map((message) => <li key={'message-' + message}>{message}</li>)}</ul>;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
61
74
|
return (
|
|
62
75
|
<AnimatePresence>
|
|
63
76
|
{visible && (
|
|
@@ -72,8 +85,8 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(
|
|
|
72
85
|
ref={ref}
|
|
73
86
|
role="status"
|
|
74
87
|
>
|
|
75
|
-
<Grid hasTitle={hasTitle}>
|
|
76
|
-
<IconContainer variant={variant}>{getIcon()}</IconContainer>
|
|
88
|
+
<Grid hasTitle={hasTitle} showIcon={showIcon}>
|
|
89
|
+
{showIcon && <IconContainer variant={variant}>{getIcon()}</IconContainer>}
|
|
77
90
|
|
|
78
91
|
{/* If title is declared set title, otherwise put everything on single line */}
|
|
79
92
|
{title && (
|
|
@@ -82,25 +95,13 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(
|
|
|
82
95
|
<div />
|
|
83
96
|
</>
|
|
84
97
|
)}
|
|
85
|
-
{
|
|
86
|
-
<p>{text}</p>
|
|
87
|
-
) : (
|
|
88
|
-
text && (
|
|
89
|
-
<ul>
|
|
90
|
-
{text.map((message) => (
|
|
91
|
-
<li key={'message-' + message}>{message}</li>
|
|
92
|
-
))}
|
|
93
|
-
</ul>
|
|
94
|
-
)
|
|
95
|
-
)}
|
|
98
|
+
{renderText()}
|
|
96
99
|
{hasTitle ? <div /> : null}
|
|
97
100
|
<ButtonContainer hasTitle={hasTitle} show={dismiss || action ? true : false} variant={variant}>
|
|
98
101
|
{action && (
|
|
99
|
-
<Button size="
|
|
100
|
-
)}
|
|
101
|
-
{dismiss && (
|
|
102
|
-
<Button size="small" color="white" variant="outline" onClick={handleDismiss} text="Dismiss" />
|
|
102
|
+
<Button size="tiny" variant="outline" onClick={handleExecute} text={action.text} color={variant} />
|
|
103
103
|
)}
|
|
104
|
+
{dismiss && <Button size="tiny" color="white" variant="outline" onClick={handleDismiss} text="Dismiss" />}
|
|
104
105
|
</ButtonContainer>
|
|
105
106
|
</Grid>
|
|
106
107
|
</Container>
|
|
@@ -58,10 +58,15 @@ export const Container = styled(motion.div)<{
|
|
|
58
58
|
}}
|
|
59
59
|
`;
|
|
60
60
|
|
|
61
|
-
export const Grid = styled.div<{ hasTitle: boolean }>`
|
|
61
|
+
export const Grid = styled.div<{ hasTitle: boolean; showIcon: boolean }>`
|
|
62
62
|
display: grid;
|
|
63
|
-
grid-template-columns: ${({ theme, hasTitle }) =>
|
|
64
|
-
|
|
63
|
+
grid-template-columns: ${({ theme, hasTitle, showIcon }) => {
|
|
64
|
+
const result = '';
|
|
65
|
+
if (showIcon) result.concat(`${theme.spacing[5]}`);
|
|
66
|
+
result.concat(' 1fr');
|
|
67
|
+
if (hasTitle) result.concat(' fit-content(100px)');
|
|
68
|
+
return result;
|
|
69
|
+
}}
|
|
65
70
|
align-items: center;
|
|
66
71
|
gap: ${({ theme, hasTitle }) => (hasTitle ? 0 : theme.spacing['0_5'])};
|
|
67
72
|
`;
|
|
@@ -83,5 +88,6 @@ export const ButtonContainer = styled.div<{
|
|
|
83
88
|
}>`
|
|
84
89
|
display: ${({ show }): string => (show ? 'flex' : 'none')};
|
|
85
90
|
align-items: center;
|
|
91
|
+
white-space: nowrap;
|
|
86
92
|
margin-top: ${({ theme, hasTitle }): string => (hasTitle ? theme.spacing['1'] : theme.spacing[0])};
|
|
87
93
|
`;
|
|
@@ -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
|
|
|
@@ -6,6 +6,13 @@ const Container = styled.div`
|
|
|
6
6
|
margin-bottom: ${({ theme }) => theme.spacing['1']};
|
|
7
7
|
hyphens: auto;
|
|
8
8
|
|
|
9
|
+
border: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
10
|
+
padding: 10px 5px 0px 5px;
|
|
11
|
+
border-top-left-radius: 0;
|
|
12
|
+
border-top-right-radius: 0;
|
|
13
|
+
border-bottom-left-radius: 5px;
|
|
14
|
+
border-bottom-right-radius: 5px;
|
|
15
|
+
|
|
9
16
|
p {
|
|
10
17
|
hypens: auto;
|
|
11
18
|
}
|
|
@@ -22,6 +22,18 @@ const Container = styled.button<{ open: boolean }>`
|
|
|
22
22
|
margin-bottom: ${({ theme, open }) => (!open ? theme.spacing['1'] : theme.spacing['0_5'])};
|
|
23
23
|
border: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
|
|
24
24
|
color: ${({ theme }) => theme.colors.textAlt};
|
|
25
|
+
font-size: ${({ theme }) => theme.fontSize.mediumLarge};
|
|
26
|
+
|
|
27
|
+
${({ open }) => {
|
|
28
|
+
if (open) {
|
|
29
|
+
return `
|
|
30
|
+
border-bottom: 0;
|
|
31
|
+
border-bottom-left-radius: 0;
|
|
32
|
+
border-bottom-right-radius: 0;
|
|
33
|
+
margin-bottom: 0;
|
|
34
|
+
`;
|
|
35
|
+
}
|
|
36
|
+
}}
|
|
25
37
|
|
|
26
38
|
svg {
|
|
27
39
|
fill: ${({ theme }) => theme.colors.textAlt};
|
|
@@ -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
|
-
`;
|