@lunit/oui 2.4.7 → 2.4.9

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,7 @@ const Segments = ({ segments, isCutoff }) => {
9
9
  return null;
10
10
  }
11
11
  const validSegments = segments.filter((segment) => segment.width > 0);
12
- const combinedWidth = segments.length > 1 ? segments[0].width + segments[1].width : 0;
12
+ const combinedWidth = segments.reduce((sum, segment) => sum + segment.width, 0);
13
13
  const onePercentSegmentIndex = _findIndex(segments, (segment) => segment.width > 0 && segment.width <= 1);
14
14
  if (segments?.length === 1 && segments[0].color === 'jet') {
15
15
  return (_jsx(Box, { sx: { width: '100%', height: '14px', transform: 'scaleY(0.8)' }, children: _jsx(HeatmapGraphSVG, {}) }));
@@ -105,7 +105,7 @@ const segmentStyle = (color, width, isFirstSegment, isLastSegment, isCutoff, com
105
105
  borderBottomRightRadius: isLastSegment ? '2px' : '0px',
106
106
  width: `${width}%`,
107
107
  };
108
- if (isOnePercentSegment) {
108
+ if (isOnePercentSegment && isCutoff) {
109
109
  return {
110
110
  ...baseStyle,
111
111
  width: '12px',
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useState } from 'react';
2
+ import { useState, useMemo, useCallback } from 'react';
3
3
  import { v4 as uuidV4 } from 'uuid';
4
4
  import { Box } from '@mui/material';
5
5
  import { BaseSlider, Container } from './Threshold.styled';
@@ -9,7 +9,7 @@ import { PresentationTypography } from '../presentations.styled';
9
9
  import { Button, Dropdown, DropdownItem } from '../../components';
10
10
  import { HorizonDivider } from '../HorizonDivider';
11
11
  import { FreeText } from '../FreeText';
12
- import { getPresetValue, getSliderMarks } from './Threshold.utils';
12
+ import { baseSliderMarks, getPresetValue } from './Threshold.utils';
13
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.");
@@ -20,28 +20,28 @@ const Threshold = ({ componentType = 'threshold', title, totalScore, totalCells,
20
20
  if (!options.length)
21
21
  throw new Error("The 'options' prop must contain at least one item.");
22
22
  const [isThresholdChanged, setIsThresholdChanged] = useState(false);
23
- const [selectedOptionValue, setSelectedOptionValue] = useState(options[0].value);
23
+ const selectedOptionValue = useMemo(() => {
24
+ return (options.find((option) => option.title === thresholdState?.selectedItem)?.value ||
25
+ options[0].value);
26
+ }, [options, thresholdState?.selectedItem]);
24
27
  const presetValue = getPresetValue(options, thresholdState?.selectedItem);
25
- const marks = getSliderMarks(presetValue);
26
- const handleDropdownChange = (event) => {
28
+ const handleDropdownChange = useCallback((event) => {
27
29
  onChangeDropdown(event);
28
- const newOption = options.find((option) => option.title === event.target.value)?.value;
29
- setSelectedOptionValue(newOption);
30
30
  setIsThresholdChanged(false);
31
- };
32
- const handleSliderChange = (event, value) => {
31
+ }, [onChangeDropdown]);
32
+ const handleSliderChange = useCallback((event, value) => {
33
33
  onChangeSlider(event, value);
34
34
  setIsThresholdChanged(value !== selectedOptionValue);
35
- };
36
- const handleUpdateConfiguration = () => {
35
+ }, [onChangeSlider, selectedOptionValue]);
36
+ const handleUpdateConfiguration = useCallback(() => {
37
37
  onClickUpdateConfiguration();
38
38
  setIsThresholdChanged(false);
39
- };
39
+ }, [onClickUpdateConfiguration]);
40
40
  return (_jsxs(Container, { children: [_jsx(Score, { ...totalScore }), _jsx(Statistic, { ...totalCells }), statisticItems.map((item) => {
41
41
  return (_jsx(Statistic, { ...item }, uuidV4()));
42
42
  }), _jsx(HorizonDivider, { componentType: "divider" }), _jsx(PresentationTypography, { size: "medium", children: title }), _jsx(Dropdown, { value: thresholdState?.selectedItem, onChange: handleDropdownChange, sx: { width: '258px' }, children: options.map((option) => {
43
43
  return (_jsx(DropdownItem, { value: option.title, children: option.title }, option.title));
44
- }) }), _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: {
44
+ }) }), _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: baseSliderMarks, onChange: handleSliderChange, onChangeCommitted: onSliderChangeCommitted }), !thresholdState?.isPresetSelected && (_jsx(Button, { id: "update-threshold-config-btn", label: "Update Configuration", sx: {
45
45
  width: '100%',
46
46
  }, 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 }))] })] }));
47
47
  };
@@ -7,7 +7,7 @@ export const Container = styled(Box)({
7
7
  });
8
8
  export const BaseSlider = styled(Slider, {
9
9
  shouldForwardProp: (prop) => prop !== 'defaultThreshold',
10
- })(({ defaultThreshold, marks }) => {
10
+ })(({ defaultThreshold, marks, disabled }) => {
11
11
  let markIndex = 0;
12
12
  if (Array.isArray(marks) && marks.length > 0) {
13
13
  markIndex = marks.findIndex((mark) => mark.value === defaultThreshold);
@@ -30,18 +30,12 @@ export const BaseSlider = styled(Slider, {
30
30
  '&.Mui-focusVisible': {
31
31
  boxShadow: `0px 0px 0px 8px rgba(255, 0, 0, 0.2)`,
32
32
  },
33
- '&.Mui-disabled': {
34
- visibility: 'hidden',
35
- },
36
33
  },
37
34
  '& .MuiSlider-mark': {
38
35
  background: theme.palette.neutralGrey[40],
39
36
  height: '6px',
40
37
  width: '6px',
41
38
  borderRadius: '50%',
42
- [defaultThresClass]: {
43
- background: theme.palette.lunitTeal[40],
44
- },
45
39
  },
46
40
  '& .MuiSlider-markLabel': {
47
41
  fontFamily: 'Pretendard,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol"',
@@ -49,9 +43,6 @@ export const BaseSlider = styled(Slider, {
49
43
  fontStyle: 'normal',
50
44
  fontWeight: '500',
51
45
  lineHeight: '12px',
52
- [defaultLabelClass]: {
53
- color: theme.palette.lunitTeal[40],
54
- },
55
46
  },
56
47
  '& .MuiSlider-valueLabel': {
57
48
  fontFamily: 'Pretendard,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol"',
@@ -63,7 +54,7 @@ export const BaseSlider = styled(Slider, {
63
54
  width: 32,
64
55
  height: 32,
65
56
  borderRadius: '50% 50% 50% 0',
66
- backgroundColor: theme.palette.lunitTeal[40],
57
+ backgroundColor: disabled ? theme.palette.neutralGrey[60] : theme.palette.lunitTeal[40],
67
58
  transformOrigin: 'bottom left',
68
59
  transform: 'translate(50%, -100%) rotate(-45deg) scale(0)',
69
60
  '&:before': { display: 'none' },
@@ -22,6 +22,6 @@ const ToggleControl = ({ componentType = 'toggle', title, size = 'medium', symbo
22
22
  return (_jsxs(ToggleControlOuter, { "data-testid": `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: {
23
23
  display: 'flex',
24
24
  alignItems: 'center',
25
- }, children: _jsx(Information, {}) }) })), symbol && (_jsx(PresentationSymbolIcon, { symbol: symbol, color: color, isDimmed: isDimmed || !checked })), _jsx(PresentationTypography, { size: size, isDimmed: isDimmed || !checked, children: title })] }), _jsx(StyledToggle, { disabled: disabled || isDimmed, checked: checked, toggleColor: theme.palette.lunitTeal[70], onChange: onChange })] }), content.length > 0 && (_jsx(Box, { sx: { display: 'flex', flexDirection: 'column', gap: '8px' }, children: content.map((item) => (_jsx(Statistic, { ...item, isDimmed: isDimmed || !checked }, uuidV4()))) }, uuidV4())), bar && (_jsx(Box, { sx: { padding: '0 8px', fontSize: '14px', lineHeight: '8px' }, children: _jsx(AnalysisBar, { isDimmed: isDimmed || !checked, componentType: bar.componentType, expressionValue: bar.expressionValue, expressionLevels: bar.expressionLevels, expressionLabels: bar.expressionLabels, caption: bar.caption, segments: bar.segments }) }))] }));
25
+ }, children: _jsx(Information, {}) }) })), symbol && (_jsx(PresentationSymbolIcon, { symbol: symbol, color: color, isDimmed: isDimmed || !checked })), _jsx(PresentationTypography, { size: size, isDimmed: isDimmed || !checked, children: title })] }), _jsx(StyledToggle, { disabled: disabled || isDimmed, checked: checked, toggleColor: theme.palette.lunitTeal[70], onChange: onChange })] }), content.length > 0 && (_jsx(Box, { sx: { display: 'flex', flexDirection: 'column', gap: '8px' }, children: content.map((item) => (_jsx(Statistic, { ...item, isDimmed: isDimmed || !checked }, uuidV4()))) }, uuidV4())), bar && (_jsx(Box, { sx: { padding: '0 8px', fontSize: '14px', lineHeight: '8px', width: '100%' }, children: _jsx(AnalysisBar, { isDimmed: isDimmed || !checked, componentType: bar.componentType, expressionValue: bar.expressionValue, expressionLevels: bar.expressionLevels, expressionLabels: bar.expressionLabels, caption: bar.caption, segments: bar.segments }) }))] }));
26
26
  };
27
27
  export default ToggleControl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunit/oui",
3
- "version": "2.4.7",
3
+ "version": "2.4.9",
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)"
@@ -11,7 +11,7 @@
11
11
  "@emotion/react": "^11.11.1",
12
12
  "@emotion/styled": "^11.11.0",
13
13
  "@lunit/design-system-icons": "^2.1.0",
14
- "@lunit/design-system-logo": "^1.1.0",
14
+ "@lunit/design-system-logo": "1.1.1",
15
15
  "@mui/icons-material": "^5.15.2",
16
16
  "@mui/lab": "^5.0.0-alpha.158",
17
17
  "@mui/material": "^5.15.2",