tycho-storybook 0.2.2 → 0.2.4

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.
@@ -1,5 +1,5 @@
1
- import { UseFormReturn } from 'react-hook-form';
2
- import './styles.scss';
1
+ import { UseFormReturn } from "react-hook-form";
2
+ import "./styles.scss";
3
3
  export type SelectItem = {
4
4
  label: string;
5
5
  value: string | number;
@@ -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 '@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';
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('ds-select-text', className, {
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
- ? '#BEBFC1'
30
+ ? "#BEBFC1"
31
31
  : hasError()
32
- ? '#C6080A'
32
+ ? "#C6080A"
33
33
  : active
34
- ? '#1C83F4'
35
- : '#000000',
36
- }, children: `${label}${required ? ' *' : ''}` }), _jsxs(Select, { ...field, value: multiple
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 ?? ''), 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) => {
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
- ? '#BEBFC1'
64
+ ? "#BEBFC1"
65
65
  : hasError()
66
- ? '#C6080A!important'
66
+ ? "#C6080A!important"
67
67
  : active
68
- ? '#1C83F4!important'
69
- : '#BEBFC1!important',
68
+ ? "#1C83F4!important"
69
+ : "#BEBFC1!important",
70
70
  backgroundColor: disabled
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('');
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 ? '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) }))] })) }) }));
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
  }
@@ -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
  }
@@ -24,3 +24,4 @@ export default meta;
24
24
  type Story = StoryObj<typeof meta>;
25
25
  export declare const Simple: Story;
26
26
  export declare const Complex: Story;
27
+ export declare const SimpleWithIcon: Story;
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import TooltipComponent, { TooltipModes } from './Tooltip';
3
+ import Icon from '../Icon';
3
4
  const meta = {
4
5
  title: 'Components/Tooltip',
5
6
  component: TooltipComponent,
@@ -38,3 +39,10 @@ export const Complex = {
38
39
  },
39
40
  },
40
41
  };
42
+ export const SimpleWithIcon = {
43
+ args: {
44
+ mode: 'simple',
45
+ title: 'Simple tooltip title',
46
+ children: (_jsx("span", { children: _jsx(Icon, { name: "help" }) })),
47
+ },
48
+ };
@@ -1,3 +1,20 @@
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
+ }
12
+
13
+ // Arrow styles scoped to our tooltip component
14
+ .ds-tooltip-popper .MuiTooltip-arrow {
15
+ color: var(--layer-tooltip) !important;
16
+ }
17
+
1
18
  .ds-tooltip {
2
19
  display: flex;
3
20
  align-items: center;
@@ -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
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-storybook",
3
3
  "private": false,
4
- "version": "0.2.2",
4
+ "version": "0.2.4",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {