tycho-storybook 0.2.1 → 0.2.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.
|
@@ -9,7 +9,14 @@ export default function IconButton({ name, className, disabled = false, active =
|
|
|
9
9
|
const getClassNames = cx("ds-icon-button", className, size, mode, color, {
|
|
10
10
|
active: !disabled && active,
|
|
11
11
|
});
|
|
12
|
-
const
|
|
12
|
+
const getIconSize = () => {
|
|
13
|
+
if (size === "large")
|
|
14
|
+
return "small";
|
|
15
|
+
if (size === "medium")
|
|
16
|
+
return "small";
|
|
17
|
+
return size;
|
|
18
|
+
};
|
|
19
|
+
const renderButton = () => (_jsx("button", { type: "button", disabled: disabled, className: getClassNames, onClick: onClick, children: _jsx(Icon, { name: name, size: getIconSize(), filled: filledIcon, className: spin ? "spin" : "" }) }));
|
|
13
20
|
if (disabled)
|
|
14
21
|
return renderButton();
|
|
15
22
|
return (_jsx(Tooltip, { title: title, placement: "top", arrow: true, children: renderButton() }));
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
|
|
3
|
-
import { FormControl, InputAdornment, InputLabel, MenuItem, Select, } from
|
|
4
|
-
import { ThemeProvider, useTheme } from
|
|
5
|
-
import cx from
|
|
6
|
-
import { useEffect, useState } from
|
|
7
|
-
import { Controller } from
|
|
8
|
-
import Icon from
|
|
9
|
-
import { selectFieldTheme } from
|
|
10
|
-
import
|
|
3
|
+
import { FormControl, InputAdornment, InputLabel, MenuItem, Select, } from "@mui/material";
|
|
4
|
+
import { ThemeProvider, useTheme } from "@mui/material/styles";
|
|
5
|
+
import cx from "classnames";
|
|
6
|
+
import { useEffect, useState } from "react";
|
|
7
|
+
import { Controller } from "react-hook-form";
|
|
8
|
+
import Icon from "../Icon";
|
|
9
|
+
import { selectFieldTheme } from "./SelectFieldTheme";
|
|
10
|
+
import "./styles.scss";
|
|
11
11
|
export default function SelectField({ className, attr, label, createdForm, disabled, title, placeholder, options = [], required, showEndAdornment = true, onChange, maxHeight = 400, multiple = false, }) {
|
|
12
12
|
const outerTheme = useTheme();
|
|
13
13
|
const [active, setActive] = useState(false);
|
|
14
14
|
const [focus, setFocus] = useState(false);
|
|
15
15
|
const [mouseOver, setMouseOver] = useState(false);
|
|
16
16
|
const hasError = () => createdForm.formState.errors[attr];
|
|
17
|
-
const getClassNames = cx(
|
|
17
|
+
const getClassNames = cx("ds-select-text", className, {
|
|
18
18
|
disabled: disabled,
|
|
19
19
|
});
|
|
20
20
|
useEffect(() => {
|
|
@@ -27,28 +27,28 @@ export default function SelectField({ className, attr, label, createdForm, disab
|
|
|
27
27
|
}, [focus, mouseOver]);
|
|
28
28
|
return (_jsx("div", { className: getClassNames, children: _jsx(Controller, { name: attr, control: createdForm.control, render: ({ field }) => (_jsxs(ThemeProvider, { theme: selectFieldTheme(outerTheme), children: [_jsxs(FormControl, { fullWidth: true, variant: "filled", disabled: disabled, children: [_jsx(InputLabel, { shrink: true, sx: {
|
|
29
29
|
color: disabled
|
|
30
|
-
?
|
|
30
|
+
? "#BEBFC1"
|
|
31
31
|
: hasError()
|
|
32
|
-
?
|
|
32
|
+
? "#C6080A"
|
|
33
33
|
: active
|
|
34
|
-
?
|
|
35
|
-
:
|
|
36
|
-
}, children: `${label}${required ?
|
|
34
|
+
? "#1C83F4"
|
|
35
|
+
: "#000000",
|
|
36
|
+
}, children: `${label}${required ? " *" : ""}` }), _jsxs(Select, { ...field, value: multiple
|
|
37
37
|
? Array.isArray(field.value)
|
|
38
38
|
? field.value
|
|
39
39
|
: []
|
|
40
|
-
: (field.value ??
|
|
40
|
+
: (field.value ?? ""), multiple: multiple, fullWidth: true, displayEmpty: true, required: required, disabled: disabled, variant: "filled", color: "primary", onFocus: () => setFocus(true), onBlur: () => setFocus(false), onMouseOver: () => setMouseOver(true), onMouseOut: () => setMouseOver(false), onChange: (event) => {
|
|
41
41
|
let value = event.target.value;
|
|
42
42
|
if (multiple) {
|
|
43
43
|
// If empty option is chosen, clear the array
|
|
44
|
-
if (Array.isArray(value) && value.includes(
|
|
44
|
+
if (Array.isArray(value) && value.includes("")) {
|
|
45
45
|
value = [];
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
49
|
// For single-select, empty string means clear
|
|
50
|
-
if (value ===
|
|
51
|
-
value =
|
|
50
|
+
if (value === "") {
|
|
51
|
+
value = "";
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
field.onChange(value);
|
|
@@ -61,17 +61,17 @@ export default function SelectField({ className, attr, label, createdForm, disab
|
|
|
61
61
|
},
|
|
62
62
|
}, sx: {
|
|
63
63
|
borderColor: disabled
|
|
64
|
-
?
|
|
64
|
+
? "#BEBFC1"
|
|
65
65
|
: hasError()
|
|
66
|
-
?
|
|
66
|
+
? "#C6080A!important"
|
|
67
67
|
: active
|
|
68
|
-
?
|
|
69
|
-
:
|
|
68
|
+
? "#1C83F4!important"
|
|
69
|
+
: "#BEBFC1!important",
|
|
70
70
|
backgroundColor: disabled
|
|
71
|
-
?
|
|
72
|
-
:
|
|
73
|
-
}, endAdornment: showEndAdornment && (_jsx(InputAdornment, { position: "end", children: field.value ? (_jsx(Icon, { name: "close", size: "small", className: disabled ?
|
|
74
|
-
field.onChange(
|
|
71
|
+
? "#BEBFC1!important"
|
|
72
|
+
: "#FFFFFF!important",
|
|
73
|
+
}, endAdornment: showEndAdornment && (_jsx(InputAdornment, { position: "end", children: field.value ? (_jsx(Icon, { name: "close", size: "small", className: disabled ? "d-none" : "", onClick: () => {
|
|
74
|
+
field.onChange("");
|
|
75
75
|
onChange && onChange(attr, null);
|
|
76
|
-
} })) : (_jsx(Icon, { name: "info", size: "small", className: `icon-info ${disabled ?
|
|
76
|
+
} })) : (_jsx(Icon, { name: "info", size: "small", className: `icon-info ${disabled ? "d-none" : ""}` })) })), children: [_jsx(MenuItem, { value: "", children: placeholder }), options.map((option, idx) => (_jsx(MenuItem, { value: option.value, children: option.label }, idx.valueOf())))] })] }), title && !hasError() && _jsx("div", { className: "helper", children: title }), hasError() && (_jsx("div", { className: "helper error", children: String(createdForm.formState.errors[attr]?.message) }))] })) }) }));
|
|
77
77
|
}
|
package/dist/Tooltip/Tooltip.js
CHANGED
|
@@ -7,10 +7,12 @@ export const TooltipModes = ['simple', 'confirmation', 'delete'];
|
|
|
7
7
|
export default function TooltipComponent({ children, mode = 'simple', placement = 'bottom', title, desc, cancel, confirm, triggerOpen, }) {
|
|
8
8
|
const renderSimple = () => (_jsx(Tooltip, { title: title, placement: placement, arrow: true, classes: {
|
|
9
9
|
tooltip: 'ds-tooltip-simple',
|
|
10
|
+
popper: 'ds-tooltip-popper',
|
|
10
11
|
}, children: children }));
|
|
11
12
|
const renderInnerComplex = () => (_jsxs("div", { className: "tooltip-box", children: [_jsxs("div", { className: "body", children: [_jsx(Icon, { name: mode === 'delete' ? 'delete' : 'help_center', size: "small", className: mode, filled: mode === 'confirmation' }), _jsxs("div", { className: "texts", children: [_jsx("div", { className: "title", children: title }), _jsx("div", { className: "desc", children: desc || '' })] })] }), _jsxs("div", { className: "footer", children: [cancel && (_jsx(Button, { text: cancel.label, size: "x-small", mode: "ghost", onClick: cancel.onClick, color: mode === 'delete' ? 'danger' : 'white', icon: cancel.icon })), confirm && (_jsx(Button, { text: confirm.label, size: "x-small", mode: "filled", onClick: confirm.onClick, color: mode === 'delete' ? 'danger' : 'white', icon: confirm.icon }))] })] }));
|
|
12
13
|
const renderComplex = () => (_jsx(Tooltip, { classes: {
|
|
13
14
|
tooltip: 'ds-tooltip',
|
|
15
|
+
popper: 'ds-tooltip-popper',
|
|
14
16
|
}, title: renderInnerComplex(), placement: placement, arrow: true, open: triggerOpen !== undefined ? triggerOpen : undefined, disableFocusListener: triggerOpen !== undefined, disableHoverListener: triggerOpen !== undefined, disableTouchListener: triggerOpen !== undefined, children: children }));
|
|
15
17
|
return mode === 'simple' ? renderSimple() : renderComplex();
|
|
16
18
|
}
|
package/dist/Tooltip/styles.scss
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
// Scoped MUI Tooltip styles - only applied to tooltips with our custom classes
|
|
2
|
+
.ds-tooltip-popper .MuiTooltip-tooltip {
|
|
3
|
+
display: flex;
|
|
4
|
+
align-items: center;
|
|
5
|
+
background-color: var(--layer-tooltip) !important;
|
|
6
|
+
height: 40px;
|
|
7
|
+
max-width: 280px;
|
|
8
|
+
padding: var(--spacing-100) var(--spacing-150);
|
|
9
|
+
border-radius: var(--radius-100);
|
|
10
|
+
@include body-medium-1;
|
|
11
|
+
margin-top: 0px !important;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Arrow styles scoped to our tooltip component
|
|
15
|
+
.ds-tooltip-popper .MuiTooltip-arrow {
|
|
16
|
+
color: var(--layer-tooltip) !important;
|
|
17
|
+
}
|
|
18
|
+
|
|
1
19
|
.ds-tooltip {
|
|
2
20
|
display: flex;
|
|
3
21
|
align-items: center;
|
package/dist/styles/main.scss
CHANGED
|
@@ -6,27 +6,6 @@
|
|
|
6
6
|
@import 'base/spacing';
|
|
7
7
|
@import 'base/tokens';
|
|
8
8
|
|
|
9
|
-
html,
|
|
10
|
-
body,
|
|
11
|
-
#root {
|
|
12
|
-
font-family: 'Work Sans', sans-serif;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.MuiTooltip-tooltip {
|
|
16
|
-
display: flex;
|
|
17
|
-
align-items: center;
|
|
18
|
-
background-color: var(--layer-tooltip) !important;
|
|
19
|
-
height: 40px;
|
|
20
|
-
max-width: 280px;
|
|
21
|
-
padding: var(--spacing-100) var(--spacing-150);
|
|
22
|
-
border-radius: var(--radius-100);
|
|
23
|
-
@include body-medium-1;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.MuiTooltip-arrow {
|
|
27
|
-
color: var(--layer-tooltip) !important;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
9
|
.pointer {
|
|
31
10
|
cursor: pointer;
|
|
32
11
|
}
|