@dreamtree-org/twreact-ui 1.0.59 → 1.0.60

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.esm.js CHANGED
@@ -10316,6 +10316,9 @@ var DatePicker = /*#__PURE__*/React__default.forwardRef(function (_ref, forwarde
10316
10316
  * - Sizes: 'sm' | 'md' | 'lg'
10317
10317
  * - Accessible (role="switch", keyboard toggle)
10318
10318
  * - Hidden input for form serialization (name prop)
10319
+ *
10320
+ * New props:
10321
+ * - topLabel, bottomLabel, rightLabel, leftLable (renders label in those positions)
10319
10322
  */
10320
10323
 
10321
10324
  var SIZE_MAP$2 = {
@@ -10336,7 +10339,6 @@ var SIZE_MAP$2 = {
10336
10339
  }
10337
10340
  };
10338
10341
  function Switch(props) {
10339
- var _ref;
10340
10342
  var id = props.id,
10341
10343
  name = props.name,
10342
10344
  checked = props.checked,
@@ -10351,9 +10353,10 @@ function Switch(props) {
10351
10353
  thumbColor = props.thumbColor,
10352
10354
  _props$className = props.className,
10353
10355
  className = _props$className === void 0 ? "" : _props$className,
10354
- label = props.label,
10355
- _props$labelPosition = props.labelPosition,
10356
- labelPosition = _props$labelPosition === void 0 ? "right" : _props$labelPosition,
10356
+ topLabel = props.topLabel,
10357
+ bottomLabel = props.bottomLabel,
10358
+ rightLabel = props.rightLabel,
10359
+ leftLable = props.leftLable,
10357
10360
  ariaLabel = props.ariaLabel;
10358
10361
  var isControlled = typeof checked === "boolean";
10359
10362
  var _useState = useState(defaultChecked),
@@ -10401,17 +10404,30 @@ function Switch(props) {
10401
10404
 
10402
10405
  // fallback when ON and no bgColor provided (keeps the switch visible)
10403
10406
  var fallbackOnClass = isOn && !bgColor ? "bg-sky-500" : "";
10407
+
10408
+ // Accessible label fallback: prefer ariaLabel, otherwise first provided visible label, otherwise "Toggle"
10409
+ var accessibleLabel = ariaLabel || rightLabel || leftLable || topLabel || bottomLabel || "Toggle";
10410
+
10411
+ // Container layout: column if top or bottom labels exist, otherwise row
10412
+ var containerIsColumn = Boolean(topLabel || bottomLabel);
10413
+ var containerClass = [containerIsColumn ? "flex flex-col items-center" : "inline-flex items-center", "gap-2", className].filter(Boolean).join(" ");
10414
+ var labelOpacityClass = disabled ? "opacity-50" : "";
10404
10415
  return /*#__PURE__*/React__default.createElement("div", {
10405
- className: "inline-flex items-center gap-2 ".concat(className)
10406
- }, label && labelPosition === "left" ? /*#__PURE__*/React__default.createElement("label", {
10416
+ className: containerClass
10417
+ }, topLabel ? /*#__PURE__*/React__default.createElement("label", {
10407
10418
  htmlFor: idRef.current,
10408
- className: disabled ? "opacity-50" : ""
10409
- }, label) : null, /*#__PURE__*/React__default.createElement("button", {
10419
+ className: labelOpacityClass
10420
+ }, topLabel) : null, /*#__PURE__*/React__default.createElement("div", {
10421
+ className: "inline-flex items-center gap-2"
10422
+ }, leftLable ? /*#__PURE__*/React__default.createElement("label", {
10423
+ htmlFor: idRef.current,
10424
+ className: labelOpacityClass
10425
+ }, leftLable) : null, /*#__PURE__*/React__default.createElement("button", {
10410
10426
  id: idRef.current,
10411
10427
  type: "button",
10412
10428
  role: "switch",
10413
10429
  "aria-checked": isOn,
10414
- "aria-label": ariaLabel,
10430
+ "aria-label": accessibleLabel,
10415
10431
  "aria-disabled": disabled || undefined,
10416
10432
  disabled: disabled,
10417
10433
  tabIndex: disabled ? -1 : 0,
@@ -10421,14 +10437,17 @@ function Switch(props) {
10421
10437
  style: trackStyle
10422
10438
  }, /*#__PURE__*/React__default.createElement("span", {
10423
10439
  className: "sr-only"
10424
- }, (_ref = ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : label) !== null && _ref !== void 0 ? _ref : "Toggle"), /*#__PURE__*/React__default.createElement("span", {
10440
+ }, accessibleLabel), /*#__PURE__*/React__default.createElement("span", {
10425
10441
  "aria-hidden": "true",
10426
10442
  className: "".concat(knobBase, " ").concat(knobTransform),
10427
10443
  style: knobStyle
10428
- })), label && labelPosition === "right" ? /*#__PURE__*/React__default.createElement("label", {
10444
+ })), rightLabel ? /*#__PURE__*/React__default.createElement("label", {
10445
+ htmlFor: idRef.current,
10446
+ className: labelOpacityClass
10447
+ }, rightLabel) : null), bottomLabel ? /*#__PURE__*/React__default.createElement("label", {
10429
10448
  htmlFor: idRef.current,
10430
- className: disabled ? "opacity-50" : ""
10431
- }, label) : null, name ? /*#__PURE__*/React__default.createElement("input", {
10449
+ className: labelOpacityClass
10450
+ }, bottomLabel) : null, name ? /*#__PURE__*/React__default.createElement("input", {
10432
10451
  type: "checkbox",
10433
10452
  name: name,
10434
10453
  readOnly: true,