sag_components 2.0.0-beta195 → 2.0.0-beta197
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.
- package/dist/index.d.ts +3 -1
- package/dist/index.esm.js +145 -31
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +145 -31
- package/dist/index.js.map +1 -1
- package/dist/types/components/WeeksPicker/WeeksCalendar.d.ts +16 -6
- package/dist/types/components/WeeksPicker/WeeksPicker.d.ts +3 -1
- package/dist/types/components/WeeksPicker/WeeksPicker.stories.d.ts +33 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12262,13 +12262,16 @@ const Td$1 = styled__default["default"].td`
|
|
|
12262
12262
|
`;
|
|
12263
12263
|
const Tr = styled__default["default"].tr`
|
|
12264
12264
|
border-bottom: 1px solid #f3f4f6;
|
|
12265
|
-
${
|
|
12266
|
-
|
|
12267
|
-
|
|
12268
|
-
|
|
12265
|
+
${_ref => {
|
|
12266
|
+
let {
|
|
12267
|
+
enableHover,
|
|
12268
|
+
selectHoverColor
|
|
12269
|
+
} = _ref;
|
|
12270
|
+
return enableHover && `&:hover {
|
|
12269
12271
|
background-color: ${selectHoverColor};
|
|
12270
12272
|
cursor: pointer;
|
|
12271
|
-
}
|
|
12273
|
+
}`;
|
|
12274
|
+
}}
|
|
12272
12275
|
`;
|
|
12273
12276
|
const InfoText = styled__default["default"].div`
|
|
12274
12277
|
font-weight: 400;
|
|
@@ -34729,6 +34732,8 @@ const ModalWithOverlay = props => {
|
|
|
34729
34732
|
}, children)));
|
|
34730
34733
|
};
|
|
34731
34734
|
|
|
34735
|
+
// src/components/WeeksPicker/WeeksCalendar.styles.js
|
|
34736
|
+
|
|
34732
34737
|
/* ──────────────────────────────────────────
|
|
34733
34738
|
COLORS – map to your design-system tokens
|
|
34734
34739
|
Change only here if the palette shifts
|
|
@@ -34740,7 +34745,9 @@ const c = {
|
|
|
34740
34745
|
primary: "#016672",
|
|
34741
34746
|
// apply / highlight
|
|
34742
34747
|
primaryLight: "#d1e7ea",
|
|
34743
|
-
border: "#e0e0e0"
|
|
34748
|
+
border: "#e0e0e0",
|
|
34749
|
+
disabled: "#f5f5f5",
|
|
34750
|
+
disabledText: "#bdbdbd"
|
|
34744
34751
|
};
|
|
34745
34752
|
|
|
34746
34753
|
/* ───────────────────────── wrapper */
|
|
@@ -34780,34 +34787,56 @@ const WeekCell = styled__default["default"].div`
|
|
|
34780
34787
|
text-align: center;
|
|
34781
34788
|
cursor: pointer;
|
|
34782
34789
|
color: ${c.textSecondary};
|
|
34783
|
-
transition: background 0.15s ease;
|
|
34784
|
-
|
|
34790
|
+
transition: background 0.15s ease, opacity 0.15s ease, color 0.15s ease;
|
|
34791
|
+
border-radius: 4px;
|
|
34785
34792
|
|
|
34793
|
+
/* Disabled state - highest priority */
|
|
34786
34794
|
${({
|
|
34787
|
-
$
|
|
34788
|
-
}) => $
|
|
34795
|
+
$disabled
|
|
34796
|
+
}) => $disabled && styled.css`
|
|
34797
|
+
opacity: 0.3;
|
|
34798
|
+
cursor: not-allowed;
|
|
34799
|
+
background: ${c.disabled} !important;
|
|
34800
|
+
color: ${c.disabledText} !important;
|
|
34801
|
+
|
|
34802
|
+
&:hover {
|
|
34803
|
+
background: ${c.disabled} !important;
|
|
34804
|
+
color: ${c.disabledText} !important;
|
|
34805
|
+
}
|
|
34806
|
+
`}
|
|
34789
34807
|
|
|
34808
|
+
/* Selected state - only if not disabled */
|
|
34809
|
+
${({
|
|
34810
|
+
$selected,
|
|
34811
|
+
$disabled
|
|
34812
|
+
}) => $selected && !$disabled && styled.css`
|
|
34790
34813
|
background: ${c.primary};
|
|
34791
34814
|
color: #FFFFFF;
|
|
34792
34815
|
`}
|
|
34793
34816
|
|
|
34794
|
-
/*
|
|
34817
|
+
/* Range middle highlighting - only if not disabled */
|
|
34795
34818
|
${({
|
|
34796
|
-
$isRangeMiddle
|
|
34797
|
-
|
|
34819
|
+
$isRangeMiddle,
|
|
34820
|
+
$disabled
|
|
34821
|
+
}) => $isRangeMiddle && !$disabled && styled.css`
|
|
34798
34822
|
background: ${c.primaryLight};
|
|
34799
34823
|
border-radius: 0px;
|
|
34800
34824
|
color: ${c.text};
|
|
34801
34825
|
`}
|
|
34802
34826
|
|
|
34803
|
-
|
|
34804
|
-
|
|
34805
|
-
|
|
34806
|
-
|
|
34827
|
+
/* Hover state - only if not disabled */
|
|
34828
|
+
${({
|
|
34829
|
+
$disabled
|
|
34830
|
+
}) => !$disabled && styled.css`
|
|
34831
|
+
&:hover {
|
|
34832
|
+
background: ${c.primaryLight};
|
|
34833
|
+
color: ${c.text};
|
|
34834
|
+
}
|
|
34835
|
+
`}
|
|
34836
|
+
|
|
34837
|
+
/* Typography */
|
|
34807
34838
|
text-align: center;
|
|
34808
34839
|
font-feature-settings: "liga" off;
|
|
34809
|
-
|
|
34810
|
-
/* Content/P3 Regular */
|
|
34811
34840
|
font-family: Poppins;
|
|
34812
34841
|
font-size: 12px;
|
|
34813
34842
|
font-style: normal;
|
|
@@ -34840,15 +34869,20 @@ styled.css`
|
|
|
34840
34869
|
}
|
|
34841
34870
|
`;
|
|
34842
34871
|
|
|
34872
|
+
// src/components/WeeksPicker/WeeksCalendar.jsx
|
|
34873
|
+
|
|
34843
34874
|
/**
|
|
34844
34875
|
* WeeksCalendar
|
|
34845
34876
|
* -------------
|
|
34846
34877
|
* Props
|
|
34847
|
-
* • year
|
|
34848
|
-
* • defaultStartWeek
|
|
34849
|
-
* • defaultEndWeek
|
|
34850
|
-
* •
|
|
34851
|
-
* •
|
|
34878
|
+
* • year — four-digit year (required)
|
|
34879
|
+
* • defaultStartWeek — number | null
|
|
34880
|
+
* • defaultEndWeek — number | null
|
|
34881
|
+
* • backgroundColor — string (default: "#066768")
|
|
34882
|
+
* • hoverBackgroundColor — string (default: "#E6F0F0")
|
|
34883
|
+
* • allowedWeekRange — { startWeek: number, endWeek: number } | null
|
|
34884
|
+
* • onApply(start,end) — callback, both numbers (inclusive)
|
|
34885
|
+
* • onCancel() — callback
|
|
34852
34886
|
*/
|
|
34853
34887
|
const WeeksCalendar = ({
|
|
34854
34888
|
year,
|
|
@@ -34856,6 +34890,8 @@ const WeeksCalendar = ({
|
|
|
34856
34890
|
defaultEndWeek = null,
|
|
34857
34891
|
backgroundColor = "#066768",
|
|
34858
34892
|
hoverBackgroundColor = "#E6F0F0",
|
|
34893
|
+
allowedWeekRange = null,
|
|
34894
|
+
// New prop for range restriction
|
|
34859
34895
|
onApply,
|
|
34860
34896
|
onCancel
|
|
34861
34897
|
}) => {
|
|
@@ -34873,14 +34909,29 @@ const WeeksCalendar = ({
|
|
|
34873
34909
|
const hasSelection = startWeek !== null;
|
|
34874
34910
|
const isRange = hasSelection && endWeek !== null && endWeek !== startWeek;
|
|
34875
34911
|
const weeks = React$1.useMemo(() => [...Array(53)].map((_, i) => i + 1), []);
|
|
34912
|
+
|
|
34913
|
+
// Check if a week is disabled based on allowed range
|
|
34914
|
+
const isWeekDisabled = week => {
|
|
34915
|
+
if (!allowedWeekRange) return false;
|
|
34916
|
+
const {
|
|
34917
|
+
startWeek: allowedStart,
|
|
34918
|
+
endWeek: allowedEnd
|
|
34919
|
+
} = allowedWeekRange;
|
|
34920
|
+
return week < allowedStart || week > allowedEnd;
|
|
34921
|
+
};
|
|
34876
34922
|
const handleCellClick = week => {
|
|
34877
|
-
//
|
|
34923
|
+
// Don't allow selection of disabled weeks
|
|
34924
|
+
if (isWeekDisabled(week)) {
|
|
34925
|
+
return;
|
|
34926
|
+
}
|
|
34878
34927
|
|
|
34928
|
+
// first click → start
|
|
34879
34929
|
if (!hasSelection) {
|
|
34880
34930
|
setStartWeek(week);
|
|
34881
34931
|
setEndWeek(null);
|
|
34882
34932
|
return;
|
|
34883
34933
|
}
|
|
34934
|
+
|
|
34884
34935
|
// second click → decide range or single
|
|
34885
34936
|
if (hasSelection && endWeek === null) {
|
|
34886
34937
|
// second click on same cell turns it to single selection
|
|
@@ -34893,6 +34944,7 @@ const WeeksCalendar = ({
|
|
|
34893
34944
|
setStartWeek(week < startWeek ? week : startWeek);
|
|
34894
34945
|
return;
|
|
34895
34946
|
}
|
|
34947
|
+
|
|
34896
34948
|
// any later click resets selection and starts over
|
|
34897
34949
|
setStartWeek(week);
|
|
34898
34950
|
setEndWeek(null);
|
|
@@ -34908,11 +34960,14 @@ const WeeksCalendar = ({
|
|
|
34908
34960
|
columns: 6
|
|
34909
34961
|
}, weeks.map(wk => {
|
|
34910
34962
|
const selected = wk === startWeek || isRange && wk >= startWeek && wk <= endWeek;
|
|
34963
|
+
const disabled = isWeekDisabled(wk);
|
|
34964
|
+
const isRangeMiddle = selected && wk !== startWeek && wk !== endWeek;
|
|
34911
34965
|
return /*#__PURE__*/React__default["default"].createElement(WeekCell, {
|
|
34912
34966
|
key: wk,
|
|
34913
34967
|
"data-week": wk,
|
|
34914
34968
|
$selected: selected,
|
|
34915
|
-
$isRangeMiddle:
|
|
34969
|
+
$isRangeMiddle: isRangeMiddle,
|
|
34970
|
+
$disabled: disabled,
|
|
34916
34971
|
onClick: () => handleCellClick(wk)
|
|
34917
34972
|
}, wk);
|
|
34918
34973
|
})), /*#__PURE__*/React__default["default"].createElement(Footer, null, /*#__PURE__*/React__default["default"].createElement(Button$1, {
|
|
@@ -34946,6 +35001,12 @@ WeeksCalendar.propTypes = {
|
|
|
34946
35001
|
year: PropTypes.number.isRequired,
|
|
34947
35002
|
defaultStartWeek: PropTypes.number,
|
|
34948
35003
|
defaultEndWeek: PropTypes.number,
|
|
35004
|
+
backgroundColor: PropTypes.string,
|
|
35005
|
+
hoverBackgroundColor: PropTypes.string,
|
|
35006
|
+
allowedWeekRange: PropTypes.shape({
|
|
35007
|
+
startWeek: PropTypes.number.isRequired,
|
|
35008
|
+
endWeek: PropTypes.number.isRequired
|
|
35009
|
+
}),
|
|
34949
35010
|
onApply: PropTypes.func.isRequired,
|
|
34950
35011
|
onCancel: PropTypes.func
|
|
34951
35012
|
};
|
|
@@ -35060,7 +35121,11 @@ const WeeksPicker = _ref => {
|
|
|
35060
35121
|
height,
|
|
35061
35122
|
withMarginBottom = true,
|
|
35062
35123
|
onChange,
|
|
35063
|
-
selectedValue
|
|
35124
|
+
selectedValue,
|
|
35125
|
+
// New props for range restriction
|
|
35126
|
+
allowedWeekRange = null,
|
|
35127
|
+
// { startWeek: number, endWeek: number } or null
|
|
35128
|
+
restrictToRange = false // boolean to enable/disable restriction
|
|
35064
35129
|
} = _ref;
|
|
35065
35130
|
const [value, setValue] = React$1.useState("");
|
|
35066
35131
|
const inputRef = React$1.useRef(null);
|
|
@@ -35103,6 +35168,18 @@ const WeeksPicker = _ref => {
|
|
|
35103
35168
|
};
|
|
35104
35169
|
};
|
|
35105
35170
|
|
|
35171
|
+
// Validate if selected weeks are within allowed range
|
|
35172
|
+
const validateWeekSelection = (startWeek, endWeek) => {
|
|
35173
|
+
if (!restrictToRange || !allowedWeekRange) {
|
|
35174
|
+
return true;
|
|
35175
|
+
}
|
|
35176
|
+
const {
|
|
35177
|
+
startWeek: allowedStart,
|
|
35178
|
+
endWeek: allowedEnd
|
|
35179
|
+
} = allowedWeekRange;
|
|
35180
|
+
return startWeek >= allowedStart && endWeek <= allowedEnd && startWeek <= endWeek;
|
|
35181
|
+
};
|
|
35182
|
+
|
|
35106
35183
|
// Get current parsed weeks from value
|
|
35107
35184
|
const {
|
|
35108
35185
|
startWeek: currentStartWeek,
|
|
@@ -35143,15 +35220,43 @@ const WeeksPicker = _ref => {
|
|
|
35143
35220
|
}
|
|
35144
35221
|
}
|
|
35145
35222
|
}, [isOpen]);
|
|
35223
|
+
|
|
35224
|
+
// Validate and clear invalid selections when allowedWeekRange changes
|
|
35225
|
+
React$1.useEffect(() => {
|
|
35226
|
+
if (restrictToRange && allowedWeekRange && value) {
|
|
35227
|
+
const {
|
|
35228
|
+
startWeek,
|
|
35229
|
+
endWeek
|
|
35230
|
+
} = parseValueToWeeks(value);
|
|
35231
|
+
if (startWeek && endWeek && !validateWeekSelection(startWeek, endWeek)) {
|
|
35232
|
+
// Clear invalid selection
|
|
35233
|
+
setValue("");
|
|
35234
|
+
onChange("");
|
|
35235
|
+
}
|
|
35236
|
+
}
|
|
35237
|
+
}, [allowedWeekRange, restrictToRange]);
|
|
35146
35238
|
const handleToggle = () => {
|
|
35147
35239
|
setIsOpen(!isOpen);
|
|
35148
35240
|
};
|
|
35149
35241
|
const onChangeEvent = e => {
|
|
35150
|
-
|
|
35151
|
-
|
|
35242
|
+
const newValue = e.target.value;
|
|
35243
|
+
|
|
35244
|
+
// If restriction is enabled, validate the manual input
|
|
35245
|
+
if (restrictToRange && allowedWeekRange && newValue) {
|
|
35246
|
+
const {
|
|
35247
|
+
startWeek,
|
|
35248
|
+
endWeek
|
|
35249
|
+
} = parseValueToWeeks(newValue);
|
|
35250
|
+
if (startWeek && endWeek && !validateWeekSelection(startWeek, endWeek)) {
|
|
35251
|
+
// Don't update if selection is outside allowed range
|
|
35252
|
+
return;
|
|
35253
|
+
}
|
|
35254
|
+
}
|
|
35255
|
+
onChange(newValue);
|
|
35256
|
+
setValue(newValue);
|
|
35152
35257
|
};
|
|
35153
35258
|
React$1.useEffect(() => {
|
|
35154
|
-
if (selectedValue) {
|
|
35259
|
+
if (selectedValue !== undefined) {
|
|
35155
35260
|
setValue(selectedValue);
|
|
35156
35261
|
}
|
|
35157
35262
|
}, [selectedValue]);
|
|
@@ -35226,8 +35331,17 @@ const WeeksPicker = _ref => {
|
|
|
35226
35331
|
defaultStartWeek: currentStartWeek,
|
|
35227
35332
|
defaultEndWeek: currentEndWeek,
|
|
35228
35333
|
backgroundColor: borderColorFocus,
|
|
35229
|
-
hoverBackgroundColor: hoverColor
|
|
35334
|
+
hoverBackgroundColor: hoverColor
|
|
35335
|
+
// Pass restriction parameters to WeeksCalendar
|
|
35336
|
+
,
|
|
35337
|
+
allowedWeekRange: restrictToRange ? allowedWeekRange : null,
|
|
35230
35338
|
onApply: (start, end) => {
|
|
35339
|
+
// Validate selection before applying
|
|
35340
|
+
if (restrictToRange && allowedWeekRange && !validateWeekSelection(start, end)) {
|
|
35341
|
+
// Show error or prevent selection
|
|
35342
|
+
console.warn('Selected weeks are outside the allowed range');
|
|
35343
|
+
return;
|
|
35344
|
+
}
|
|
35231
35345
|
const tempValue = end === start ? `Week ${start}` : `Weeks ${start} - ${end}`;
|
|
35232
35346
|
onChange(tempValue);
|
|
35233
35347
|
setValue(tempValue);
|