@lunit/oui 2.2.27 → 2.2.29

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,8 +10,6 @@ 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.");
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) }))] }));
13
+ return (_jsxs(PresentationTypography, { size: size, style: { color: metrics.isFullColored ? metrics.color : 'inherit' }, children: [title, metrics.value !== undefined ? `: ${metrics.value}` : '', metrics.scoreType && (_jsx("span", { style: { color: metrics.color, marginLeft: 4 }, children: capitalize(metrics.scoreType) }))] }));
16
14
  };
17
15
  export default Score;
@@ -4,7 +4,7 @@ interface ScoreProps {
4
4
  title: string;
5
5
  size?: PresentationElementSize;
6
6
  metrics: {
7
- value: string;
7
+ value?: string;
8
8
  scoreType?: 'positive' | 'negative';
9
9
  color?: string;
10
10
  isFullColored?: boolean;
@@ -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;
@@ -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';
@@ -14,9 +15,9 @@ const ToggleControlGroup = ({ componentType = 'toggleGroup', size = 'medium', ti
14
15
  if (!childToggles.length)
15
16
  throw new Error("The 'childToggles' prop must contain at least one child toggle.");
16
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) => {
17
- 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) => {
18
19
  child.onChange(event);
19
- }, bar: child.bar }, uuidV4()));
20
+ }, bar: child.bar }));
20
21
  })] }));
21
22
  };
22
23
  export default ToggleControlGroup;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunit/oui",
3
- "version": "2.2.27",
3
+ "version": "2.2.29",
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)"