@dt-dds/react-checkbox 1.0.0-beta.61 → 1.0.0-beta.63

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @dt-ui/react-checkbox
2
2
 
3
+ ## 1.0.0-beta.63
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: checkbox box width reduction on long label
8
+
9
+ ## 1.0.0-beta.62
10
+
11
+ ### Minor Changes
12
+
13
+ - feat: change theme icons to sharp
14
+
15
+ ### Patch Changes
16
+
17
+ - fix: checkbox label alignment
18
+ - Updated dependencies
19
+ - @dt-dds/react-icon@1.0.0-beta.62
20
+ - @dt-dds/themes@1.0.0-beta.14
21
+ - @dt-dds/react-core@1.0.0-beta.59
22
+
3
23
  ## 1.0.0-beta.61
4
24
 
5
25
  ### Patch Changes
package/dist/index.js CHANGED
@@ -74,6 +74,11 @@ var SIZES = {
74
74
  small: 20,
75
75
  large: 24
76
76
  };
77
+ var LABEL_HEIGHT_BUFFER = 1;
78
+ var LABEL_LINE_HEIGHT = {
79
+ small: 16,
80
+ large: 20
81
+ };
77
82
 
78
83
  // src/Checkbox.styled.ts
79
84
  var getCheckboxColors = (theme) => ({
@@ -150,6 +155,7 @@ var CheckboxBoxStyled = (0, import_styled.default)("div", {
150
155
  align-items: center;
151
156
  justify-content: center;
152
157
  border-radius: ${({ theme }) => theme.shape.checkbox};
158
+ flex-shrink: 0;
153
159
 
154
160
  ${({ theme, $checked, $indeterminate, $disabled, $error, $size }) => {
155
161
  const state = getCheckboxState(
@@ -242,11 +248,21 @@ var Checkbox = (0, import_react.forwardRef)(
242
248
  const theme = (0, import_react2.useTheme)();
243
249
  const internalRef = (0, import_react.useRef)(null);
244
250
  const mergedRef = mergeRefs(internalRef, ref);
251
+ const labelRef = (0, import_react.useRef)(null);
245
252
  (0, import_react.useEffect)(() => {
246
253
  if (internalRef.current) {
247
254
  internalRef.current.indeterminate = isIndeterminate;
248
255
  }
249
256
  }, [isIndeterminate]);
257
+ (0, import_react.useLayoutEffect)(() => {
258
+ if (!labelRef.current) return;
259
+ const labelContainer = labelRef.current.closest("label");
260
+ if (!labelContainer) return;
261
+ const el = labelRef.current;
262
+ const maxSingleLineHeight = LABEL_LINE_HEIGHT[size] + LABEL_HEIGHT_BUFFER;
263
+ const isWrapped = el.offsetHeight > maxSingleLineHeight;
264
+ labelContainer.style.alignItems = isWrapped ? "flex-start" : "center";
265
+ }, [label, children]);
250
266
  const handleChange = (event) => {
251
267
  if (isDisabled) return;
252
268
  onChange == null ? void 0 : onChange(event);
@@ -301,7 +317,15 @@ var Checkbox = (0, import_react.forwardRef)(
301
317
  ) : null
302
318
  }
303
319
  ),
304
- hasLabel ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckboxLabelStyled, { $disabled: isDisabled, $size: size, children: label || children }) : null
320
+ hasLabel ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
321
+ CheckboxLabelStyled,
322
+ {
323
+ $disabled: isDisabled,
324
+ $size: size,
325
+ ref: labelRef,
326
+ children: label || children
327
+ }
328
+ ) : null
305
329
  ]
306
330
  }
307
331
  );
package/dist/index.mjs CHANGED
@@ -28,7 +28,12 @@ var __objRest = (source, exclude) => {
28
28
  };
29
29
 
30
30
  // src/Checkbox.tsx
31
- import { forwardRef, useEffect, useRef } from "react";
31
+ import {
32
+ forwardRef,
33
+ useEffect,
34
+ useLayoutEffect,
35
+ useRef
36
+ } from "react";
32
37
  import { useTheme } from "@emotion/react";
33
38
  import { Icon } from "@dt-dds/react-icon";
34
39
 
@@ -41,6 +46,11 @@ var SIZES = {
41
46
  small: 20,
42
47
  large: 24
43
48
  };
49
+ var LABEL_HEIGHT_BUFFER = 1;
50
+ var LABEL_LINE_HEIGHT = {
51
+ small: 16,
52
+ large: 20
53
+ };
44
54
 
45
55
  // src/Checkbox.styled.ts
46
56
  var getCheckboxColors = (theme) => ({
@@ -117,6 +127,7 @@ var CheckboxBoxStyled = styled("div", {
117
127
  align-items: center;
118
128
  justify-content: center;
119
129
  border-radius: ${({ theme }) => theme.shape.checkbox};
130
+ flex-shrink: 0;
120
131
 
121
132
  ${({ theme, $checked, $indeterminate, $disabled, $error, $size }) => {
122
133
  const state = getCheckboxState(
@@ -209,11 +220,21 @@ var Checkbox = forwardRef(
209
220
  const theme = useTheme();
210
221
  const internalRef = useRef(null);
211
222
  const mergedRef = mergeRefs(internalRef, ref);
223
+ const labelRef = useRef(null);
212
224
  useEffect(() => {
213
225
  if (internalRef.current) {
214
226
  internalRef.current.indeterminate = isIndeterminate;
215
227
  }
216
228
  }, [isIndeterminate]);
229
+ useLayoutEffect(() => {
230
+ if (!labelRef.current) return;
231
+ const labelContainer = labelRef.current.closest("label");
232
+ if (!labelContainer) return;
233
+ const el = labelRef.current;
234
+ const maxSingleLineHeight = LABEL_LINE_HEIGHT[size] + LABEL_HEIGHT_BUFFER;
235
+ const isWrapped = el.offsetHeight > maxSingleLineHeight;
236
+ labelContainer.style.alignItems = isWrapped ? "flex-start" : "center";
237
+ }, [label, children]);
217
238
  const handleChange = (event) => {
218
239
  if (isDisabled) return;
219
240
  onChange == null ? void 0 : onChange(event);
@@ -268,7 +289,15 @@ var Checkbox = forwardRef(
268
289
  ) : null
269
290
  }
270
291
  ),
271
- hasLabel ? /* @__PURE__ */ jsx(CheckboxLabelStyled, { $disabled: isDisabled, $size: size, children: label || children }) : null
292
+ hasLabel ? /* @__PURE__ */ jsx(
293
+ CheckboxLabelStyled,
294
+ {
295
+ $disabled: isDisabled,
296
+ $size: size,
297
+ ref: labelRef,
298
+ children: label || children
299
+ }
300
+ ) : null
272
301
  ]
273
302
  }
274
303
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dt-dds/react-checkbox",
3
- "version": "1.0.0-beta.61",
3
+ "version": "1.0.0-beta.63",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js"
@@ -20,9 +20,9 @@
20
20
  "test:update:snapshot": "jest -u"
21
21
  },
22
22
  "dependencies": {
23
- "@dt-dds/react-core": "1.0.0-beta.58",
24
- "@dt-dds/react-icon": "1.0.0-beta.61",
25
- "@dt-dds/themes": "1.0.0-beta.13"
23
+ "@dt-dds/react-core": "1.0.0-beta.59",
24
+ "@dt-dds/react-icon": "1.0.0-beta.62",
25
+ "@dt-dds/themes": "1.0.0-beta.14"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@babel/core": "^7.22.9",