@lunit/oui 2.2.26 → 2.2.28

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.
@@ -11,8 +11,8 @@ import { Accordion } from '../Accordion';
11
11
  import { Statistic } from '../Statistic';
12
12
  import { Score } from '../Score';
13
13
  import { FreeText } from '../FreeText';
14
- import { Threshold } from '../Threshold';
15
14
  import { Histogram } from '../Histogram';
15
+ import ThresholdControl from './ThresholdControl';
16
16
  const Preview = ({ visualizationControls = [], analysisSummary = [] }) => {
17
17
  const [controls, setControls] = useState(visualizationControls);
18
18
  return (_jsxs(Container, { children: [_jsx(Box, { sx: { display: 'flex', flexDirection: 'column', gap: '16px', padding: '16px' }, children: visualizationControls.map((item, index) => {
@@ -55,6 +55,6 @@ const Preview = ({ visualizationControls = [], analysisSummary = [] }) => {
55
55
  });
56
56
  }
57
57
  return (_jsxs(Box, { children: [item.componentType === 'toggle' && (_jsx(ToggleControl, { ...item }, uuidV4())), item.componentType === 'toggleGroup' && (_jsx(ToggleControlGroup, { ...item }, uuidV4())), item.componentType === 'analysisBar' && (_jsx(AnalysisBar, { ...item }, uuidV4()))] }, uuidV4()));
58
- }) }), _jsx(HorizonDivider, { componentType: "divider" }), _jsxs(Box, { sx: { display: 'flex', flexDirection: 'column', gap: '16px', padding: '16px' }, children: [_jsx(FreeText, { componentType: "freeText", size: "medium-bold", content: "Analysis Summary" }), analysisSummary.map((item) => (_jsxs(Box, { children: [item.componentType === 'accordion' && (_jsx(Accordion, { ...item }, uuidV4())), item.componentType === 'analysisBar' && (_jsx(AnalysisBar, { ...item }, uuidV4())), item.componentType === 'statistic' && (_jsx(Statistic, { ...item }, uuidV4())), item.componentType === 'score' && (_jsx(Score, { ...item }, uuidV4())), item.componentType === 'freeText' && (_jsx(FreeText, { ...item }, uuidV4())), item.componentType === 'threshold' && (_jsx(Threshold, { ...item, onChangeDropdown: () => { }, onSliderChangeCommitted: () => { }, onClickUpdateConfiguration: () => { } }, uuidV4())), item.componentType === 'histogram' && (_jsx(Histogram, { ...item }, uuidV4()))] }, uuidV4())))] })] }));
58
+ }) }), _jsx(HorizonDivider, { componentType: "divider" }), _jsxs(Box, { sx: { display: 'flex', flexDirection: 'column', gap: '16px', padding: '16px' }, children: [_jsx(FreeText, { componentType: "freeText", size: "medium-bold", content: "Analysis Summary" }), analysisSummary.map((item) => (_jsxs(Box, { children: [item.componentType === 'accordion' && (_jsx(Accordion, { ...item }, uuidV4())), item.componentType === 'analysisBar' && (_jsx(AnalysisBar, { ...item }, uuidV4())), item.componentType === 'statistic' && (_jsx(Statistic, { ...item }, uuidV4())), item.componentType === 'score' && (_jsx(Score, { ...item }, uuidV4())), item.componentType === 'freeText' && (_jsx(FreeText, { ...item }, uuidV4())), item.componentType === 'threshold' && (_jsx(ThresholdControl, { ...item }, uuidV4())), item.componentType === 'histogram' && (_jsx(Histogram, { ...item }, uuidV4()))] }, uuidV4())))] })] }));
59
59
  };
60
60
  export default Preview;
@@ -0,0 +1,3 @@
1
+ import { type ThresholdProps } from '../Threshold';
2
+ declare const ThresholdControl: (threshold: ThresholdProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default ThresholdControl;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Threshold } from '../Threshold';
4
+ const ThresholdControl = (threshold) => {
5
+ const [selectedItem, setSelectedItem] = useState(threshold?.options[0].title.toString());
6
+ const [sliderValue, setSliderValue] = useState(threshold?.options[0].value);
7
+ const [isPresetSelected, setIsPresetSelected] = useState(threshold?.options[0].isPreset || false);
8
+ const onChangeDropdown = (event) => {
9
+ setSelectedItem(event.target.value);
10
+ setSliderValue(threshold.options.find((option) => option.title === event.target.value)?.value);
11
+ setIsPresetSelected(threshold.options.find((option) => option.title === event.target.value)?.isPreset || false);
12
+ };
13
+ const onChangeSlider = (event, value) => {
14
+ setSliderValue(value);
15
+ };
16
+ const onSliderChangeCommitted = (event, value) => { };
17
+ const onClickUpdateConfiguration = () => { };
18
+ return (_jsx(Threshold, { ...threshold, thresholdState: {
19
+ selectedItem,
20
+ sliderValue,
21
+ isPresetSelected,
22
+ }, onChangeDropdown: onChangeDropdown, onChangeSlider: onChangeSlider, onSliderChangeCommitted: onSliderChangeCommitted, onClickUpdateConfiguration: onClickUpdateConfiguration }));
23
+ };
24
+ export default ThresholdControl;
@@ -10,6 +10,8 @@ const Score = ({ componentType = 'score', title, size = 'medium', metrics }) =>
10
10
  throw new Error("The 'title' prop is required.");
11
11
  if (!metrics)
12
12
  throw new Error("The 'metrics' prop is required.");
13
+ if (metrics && !metrics.value)
14
+ throw new Error("The 'value' prop in 'metrics' is required.");
13
15
  return (_jsxs(PresentationTypography, { size: size, style: { color: metrics.isFullColored ? metrics.color : 'inherit' }, children: [title, ": ", metrics.value, metrics.scoreType && (_jsx("span", { style: { color: metrics.color, marginLeft: 4 }, children: capitalize(metrics.scoreType) }))] }));
14
16
  };
15
17
  export default Score;
@@ -1,3 +1,3 @@
1
1
  import { ThresholdProps } from './Threshold.types';
2
- declare const Threshold: ({ componentType, title, totalScore, totalCells, statisticItems, options, description, controlStep, isLoading, onChangeDropdown, onSliderChangeCommitted, onClickUpdateConfiguration, }: ThresholdProps) => import("react/jsx-runtime").JSX.Element;
2
+ declare const Threshold: ({ componentType, title, totalScore, totalCells, statisticItems, options, description, controlStep, isLoading, thresholdState, onChangeDropdown, onChangeSlider, onSliderChangeCommitted, onClickUpdateConfiguration, }: ThresholdProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default Threshold;
@@ -10,7 +10,7 @@ import { Button, Dropdown, DropdownItem } from '../../components';
10
10
  import { HorizonDivider } from '../HorizonDivider';
11
11
  import { FreeText } from '../FreeText';
12
12
  import { getPresetValue, getSliderMarks } from './Threshold.utils';
13
- const Threshold = ({ componentType = 'threshold', title, totalScore, totalCells, statisticItems, options, description, controlStep = 1, isLoading = false, onChangeDropdown, onSliderChangeCommitted, onClickUpdateConfiguration, }) => {
13
+ const Threshold = ({ componentType = 'threshold', title, totalScore, totalCells, statisticItems, options, description, controlStep = 1, isLoading = false, thresholdState, onChangeDropdown, onChangeSlider, onSliderChangeCommitted, onClickUpdateConfiguration, }) => {
14
14
  if (!componentType)
15
15
  throw new Error("The 'componentType' prop is required.");
16
16
  if (!totalScore)
@@ -19,22 +19,16 @@ const Threshold = ({ componentType = 'threshold', title, totalScore, totalCells,
19
19
  throw new Error("The 'statisticItems' prop must contain at least one item.");
20
20
  if (!options.length)
21
21
  throw new Error("The 'options' prop must contain at least one item.");
22
- const [selectedItem, setSelectedItem] = useState(options[0].title.toString());
23
- const [selectedValue, setSelectedValue] = useState(options[0].value);
24
- const [selectedOptionValue, setSelectedOptionValue] = useState(options[0].value);
25
- const [isPresetSelected, setIsPresetSelected] = useState(options[0].isPreset);
26
22
  const [isThresholdChanged, setIsThresholdChanged] = useState(false);
27
- const presetValue = getPresetValue(options, selectedItem);
23
+ const [selectedOptionValue, setSelectedOptionValue] = useState(options[0].value);
24
+ const presetValue = getPresetValue(options, thresholdState?.selectedItem);
28
25
  const marks = getSliderMarks(presetValue);
29
- const handleChange = (event) => {
30
- setSelectedItem(event.target.value);
31
- setSelectedValue(options.find((option) => option.title === event.target.value)?.value);
32
- setSelectedOptionValue(options.find((option) => option.title === event.target.value)?.value);
33
- setIsPresetSelected(options.find((option) => option.title === event.target.value)?.isPreset || false);
26
+ const handleDropdownChange = (event) => {
34
27
  onChangeDropdown(event);
28
+ setSelectedOptionValue(options.find((option) => option.title === event.target.value)?.value);
35
29
  };
36
30
  const handleSliderChange = (event, value) => {
37
- setSelectedValue(value);
31
+ onChangeSlider(event, value);
38
32
  setIsThresholdChanged(value !== selectedOptionValue);
39
33
  };
40
34
  const handleUpdateConfiguration = () => {
@@ -43,10 +37,10 @@ const Threshold = ({ componentType = 'threshold', title, totalScore, totalCells,
43
37
  };
44
38
  return (_jsxs(Container, { children: [_jsx(Score, { ...totalScore }), _jsx(Statistic, { ...totalCells }), statisticItems.map((item) => {
45
39
  return (_jsx(Statistic, { ...item }, uuidV4()));
46
- }), _jsx(HorizonDivider, { componentType: "divider" }), _jsx(PresentationTypography, { size: "medium", children: title }), _jsx(Dropdown, { value: selectedItem, onChange: handleChange, sx: { width: '258px' }, children: options.map((option) => {
40
+ }), _jsx(HorizonDivider, { componentType: "divider" }), _jsx(PresentationTypography, { size: "medium", children: title }), _jsx(Dropdown, { value: thresholdState?.selectedItem, onChange: handleDropdownChange, sx: { width: '258px' }, children: options.map((option) => {
47
41
  return (_jsx(DropdownItem, { value: option.title, children: option.title }, option.title));
48
- }) }), _jsxs(Box, { sx: { display: 'flex', flexDirection: 'column', paddingTop: '36px', gap: '6px' }, children: [_jsx(BaseSlider, { disabled: isPresetSelected, step: controlStep, value: selectedValue, valueLabelDisplay: "on", defaultThreshold: presetValue, marks: marks, onChange: handleSliderChange, onChangeCommitted: onSliderChangeCommitted }), !isPresetSelected && (_jsx(Button, { id: "update-threshold-config-btn", label: "Update Configuration", sx: {
42
+ }) }), _jsxs(Box, { sx: { display: 'flex', flexDirection: 'column', paddingTop: '36px', gap: '6px' }, children: [_jsx(BaseSlider, { disabled: thresholdState?.isPresetSelected, step: controlStep, value: thresholdState?.sliderValue, valueLabelDisplay: "on", defaultThreshold: presetValue, marks: marks, onChange: handleSliderChange, onChangeCommitted: onSliderChangeCommitted }), !thresholdState?.isPresetSelected && (_jsx(Button, { id: "update-threshold-config-btn", label: "Update Configuration", sx: {
49
43
  width: '100%',
50
- }, disabled: !isThresholdChanged || isLoading, onClick: handleUpdateConfiguration, loading: isLoading })), isPresetSelected && description?.preset && (_jsx(FreeText, { componentType: "freeText", size: "small-dimmed", content: description.preset })), !isPresetSelected && description?.user && (_jsx(FreeText, { componentType: "freeText", size: "small-dimmed", content: description.user }))] })] }));
44
+ }, disabled: !isThresholdChanged || isLoading, onClick: handleUpdateConfiguration, loading: isLoading })), thresholdState?.isPresetSelected && description?.preset && (_jsx(FreeText, { componentType: "freeText", size: "small-dimmed", content: description.preset })), !thresholdState?.isPresetSelected && description?.user && (_jsx(FreeText, { componentType: "freeText", size: "small-dimmed", content: description.user }))] })] }));
51
45
  };
52
46
  export default Threshold;
@@ -23,7 +23,13 @@ export interface ThresholdSpec {
23
23
  controlStep?: number;
24
24
  }
25
25
  export interface ThresholdProps extends ThresholdSpec {
26
+ thresholdState?: {
27
+ selectedItem: string;
28
+ sliderValue: number;
29
+ isPresetSelected: boolean;
30
+ };
26
31
  onChangeDropdown: (event: SelectChangeEvent) => void;
32
+ onChangeSlider: (event: Event | SyntheticEvent, value: number | number[]) => void;
27
33
  onSliderChangeCommitted: (event: Event | SyntheticEvent, value: number | number[]) => void;
28
34
  onClickUpdateConfiguration: () => void;
29
35
  isLoading?: boolean;
@@ -17,6 +17,8 @@ const ToggleControl = ({ componentType = 'toggle', title, size = 'medium', symbo
17
17
  throw new Error("The 'title' prop is required.");
18
18
  if (checked === undefined)
19
19
  throw new Error("The 'checked' prop is required.");
20
+ if (typeof checked !== 'boolean')
21
+ throw new Error("The 'checked' prop must be a boolean.");
20
22
  return (_jsxs(ToggleControlOuter, { "data-toggle-name": `toggle-control-${title?.replace(/\s/g, '-')}`, hasBar: !!bar || !!content.length, style: { marginBottom: isParent ? '4px' : '0' }, children: [_jsxs(ToggleControlContainer, { className: "toggle-inner-container", size: size, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: '6px' }, className: "toggle-label", children: [!!tooltip.length && (_jsx(Tooltip, { arrow: true, size: "large", title: _jsx(Box, { sx: { display: 'flex', flexDirection: 'column', gap: '8px' }, children: tooltip.map((item) => (_jsxs(Box, { children: [item.componentType === 'freeText' && (_jsx(FreeText, { componentType: item.componentType, size: item.size, content: item.content })), item.componentType === 'statistic' && (_jsx(Statistic, { componentType: item.componentType, title: item.title, size: item.size, layout: item.layout, symbol: item.symbol, color: item.color }))] }, uuidV4()))) }), children: _jsx(Box, { sx: {
21
23
  display: 'flex',
22
24
  alignItems: 'center',
@@ -1,3 +1,4 @@
1
+ import { createElement as _createElement } from "react";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import { v4 as uuidV4 } from 'uuid';
3
4
  import { ToggleControlGroupContainer } from './ToggleControlGroup.styled';
@@ -9,12 +10,14 @@ const ToggleControlGroup = ({ componentType = 'toggleGroup', size = 'medium', ti
9
10
  throw new Error("The 'title' prop is required.");
10
11
  if (checked === undefined)
11
12
  throw new Error("The 'checked' prop is required.");
13
+ if (typeof checked !== 'boolean')
14
+ throw new Error("The 'checked' prop must be a boolean.");
12
15
  if (!childToggles.length)
13
16
  throw new Error("The 'childToggles' prop must contain at least one child toggle.");
14
17
  return (_jsxs(ToggleControlGroupContainer, { children: [_jsx(ToggleControl, { isParent: true, componentType: "toggle", bar: bar, disabled: disabled, size: size, title: title, tooltip: tooltip, checked: checked, isDimmed: isDimmed, onChange: onChange }), childToggles?.map((child, index) => {
15
- return (_jsx(ToggleControl, { componentType: "toggle", title: child.title, size: child.size, tooltip: child.tooltip, symbol: child.symbol, color: child.color, isDimmed: child.isDimmed || isDimmed || !checked, checked: child.checked, disabled: child.disabled || !checked, onChange: (event) => {
18
+ return (_createElement(ToggleControl, { ...child, componentType: "toggle", key: uuidV4(), isDimmed: child.isDimmed || isDimmed || !checked, disabled: child.disabled || !checked, onChange: (event) => {
16
19
  child.onChange(event);
17
- }, bar: child.bar }, uuidV4()));
20
+ }, bar: child.bar }));
18
21
  })] }));
19
22
  };
20
23
  export default ToggleControlGroup;
@@ -22,6 +22,7 @@ export const PresentationTypography = (props) => {
22
22
  return (_jsx(Typography, { variant: "body5", ...rest, sx: { color: isDimmed ? theme.palette.neutralGrey[40] : 'inherit' } }));
23
23
  };
24
24
  export const PresentationSymbolIcon = ({ symbol, color = 'black', isDimmed = false, }) => {
25
+ const symbolColor = color?.length ? color : 'black';
25
26
  if (symbol === 'circle') {
26
27
  return (_jsx("div", { style: {
27
28
  height: '100%',
@@ -31,7 +32,7 @@ export const PresentationSymbolIcon = ({ symbol, color = 'black', isDimmed = fal
31
32
  }, children: _jsx("span", { style: {
32
33
  height: '6px',
33
34
  width: '6px',
34
- backgroundColor: color,
35
+ backgroundColor: symbolColor,
35
36
  borderRadius: '50%',
36
37
  border: '1px solid black',
37
38
  } }) }));
@@ -45,7 +46,7 @@ export const PresentationSymbolIcon = ({ symbol, color = 'black', isDimmed = fal
45
46
  }, children: _jsx("span", { style: {
46
47
  height: '10px',
47
48
  width: '10px',
48
- backgroundColor: color,
49
+ backgroundColor: symbolColor,
49
50
  } }) }));
50
51
  }
51
52
  if (symbol === 'border-circle') {
@@ -57,7 +58,7 @@ export const PresentationSymbolIcon = ({ symbol, color = 'black', isDimmed = fal
57
58
  }, children: _jsx("span", { style: {
58
59
  height: '10px',
59
60
  width: '10px',
60
- backgroundColor: color,
61
+ backgroundColor: symbolColor,
61
62
  borderRadius: '50%',
62
63
  border: '1px solid black',
63
64
  } }) }));
@@ -71,7 +72,7 @@ export const PresentationSymbolIcon = ({ symbol, color = 'black', isDimmed = fal
71
72
  }, children: _jsx("span", { style: {
72
73
  height: '10px',
73
74
  width: '10px',
74
- backgroundColor: color,
75
+ backgroundColor: symbolColor,
75
76
  border: '1px solid black',
76
77
  } }) }));
77
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunit/oui",
3
- "version": "2.2.26",
3
+ "version": "2.2.28",
4
4
  "validate-branch-name": {
5
5
  "pattern": "^(main|develop)|(feature|fix|release|hotfix|qe)/.+$",
6
6
  "errorMsg": "The branch name is not correct. Please check the pattern. (ex. feature/add-something)"