@mirohq/design-system-calendar 0.1.82 → 0.2.1

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/main.js CHANGED
@@ -10,8 +10,13 @@ var reactAria = require('react-aria');
10
10
  var date = require('@internationalized/date');
11
11
  var reactStately = require('react-stately');
12
12
  var designSystemFlex = require('@mirohq/design-system-flex');
13
- var designSystemIcons = require('@mirohq/design-system-icons');
14
13
  var designSystemButton = require('@mirohq/design-system-button');
14
+ var designSystemBaseForm = require('@mirohq/design-system-base-form');
15
+ var designSystemIcons = require('@mirohq/design-system-icons');
16
+ var designSystemBaseTextField = require('@mirohq/design-system-base-text-field');
17
+ var designSystemStyles = require('@mirohq/design-system-styles');
18
+ var designSystemTooltip = require('@mirohq/design-system-tooltip');
19
+ var designSystemBaseButton = require('@mirohq/design-system-base-button');
15
20
 
16
21
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
22
 
@@ -33,111 +38,8 @@ function _interopNamespace(e) {
33
38
  return Object.freeze(n);
34
39
  }
35
40
 
36
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
37
41
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
38
-
39
- const StyledDataSegment = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
40
- color: "$text-neutrals-subtle",
41
- "&[data-value]": {
42
- color: "$text-neutrals"
43
- },
44
- "& span": {
45
- pointerEvents: "none",
46
- "&[data-placeholder]": {
47
- display: "none",
48
- height: "0",
49
- color: "$text-neutrals-subtle"
50
- }
51
- }
52
- });
53
-
54
- const FieldDateSegment = ({ segment, state }) => {
55
- const ref = React.useRef(null);
56
- const { segmentProps } = reactAria.useDateSegment(segment, state, ref);
57
- const segmentPropsStyle = segmentProps.style;
58
- delete segmentProps.style;
59
- return /* @__PURE__ */ jsxRuntime.jsxs(
60
- StyledDataSegment,
61
- {
62
- ...segmentProps,
63
- UNSAFE_style: segmentPropsStyle,
64
- ref,
65
- "data-value": state.value !== null ? "" : void 0,
66
- children: [
67
- /* @__PURE__ */ jsxRuntime.jsx(
68
- "span",
69
- {
70
- "aria-hidden": "true",
71
- "data-placeholder": !segment.isPlaceholder ? "" : void 0,
72
- children: segment.placeholder
73
- }
74
- ),
75
- segment.isPlaceholder ? "" : segment.text
76
- ]
77
- }
78
- );
79
- };
80
- const TextField = React__default["default"].forwardRef((props, forwardRef) => {
81
- const ref = React.useRef(null);
82
- const { locale } = reactAria.useLocale();
83
- const state = reactStately.useDateFieldState({
84
- ...props,
85
- isReadOnly: true,
86
- locale,
87
- createCalendar: date.createCalendar
88
- });
89
- const { fieldProps } = reactAria.useDateField(props, state, ref);
90
- return /* @__PURE__ */ jsxRuntime.jsx(designSystemFlex.Flex, { ...fieldProps, ref: forwardRef, children: state.segments.map((segment, i) => /* @__PURE__ */ jsxRuntime.jsx(FieldDateSegment, { segment, state }, i)) });
91
- });
92
-
93
- const StyledButton = designSystemStitches.styled(designSystemPrimitive.Primitive.button, {
94
- padding: "0",
95
- backgroundColor: "$transparent",
96
- border: "none",
97
- cursor: "pointer",
98
- color: "$text-neutrals",
99
- "&[disabled]": {
100
- cursor: "not-allowed"
101
- }
102
- });
103
- const StyledFieldButton = designSystemStitches.styled(designSystemPrimitive.Primitive.button, {
104
- padding: "0",
105
- backgroundColor: "$transparent",
106
- border: "none",
107
- cursor: "pointer",
108
- square: "28px",
109
- "&[disabled]": {
110
- cursor: "not-allowed"
111
- },
112
- "& svg": {
113
- color: "$text-neutrals-subtle",
114
- square: "22px"
115
- },
116
- "&[data-custom]": {
117
- width: "100%",
118
- height: "unset"
119
- }
120
- });
121
-
122
- const Button = React__default["default"].forwardRef((props, forwardRef) => {
123
- const { buttonProps } = reactAria.useButton(props, forwardRef);
124
- const { focusProps } = reactAria.useFocusRing();
125
- const { children } = props;
126
- return /* @__PURE__ */ jsxRuntime.jsx(StyledButton, { ...reactAria.mergeProps(buttonProps, focusProps), ref: forwardRef, children });
127
- });
128
- const FieldButton = React__default["default"].forwardRef((props, forwardRef) => {
129
- const { buttonProps } = reactAria.useButton(props, forwardRef);
130
- const { customButton = false, children } = props;
131
- return /* @__PURE__ */ jsxRuntime.jsx(
132
- StyledFieldButton,
133
- {
134
- "data-custom": customButton ? "" : void 0,
135
- ...buttonProps,
136
- ref: forwardRef,
137
- children
138
- }
139
- );
140
- });
42
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
141
43
 
142
44
  const Popover = (props) => {
143
45
  const ref = React__namespace.useRef(null);
@@ -160,29 +62,8 @@ const Popover = (props) => {
160
62
  ] });
161
63
  };
162
64
 
163
- const StyledPickerInput = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
164
- display: "flex",
165
- alignItems: "center",
166
- paddingLeft: "$150",
167
- paddingRight: "$100",
168
- border: "1px solid $border-neutrals",
169
- borderRadius: "$50",
170
- background: "$background-neutrals",
171
- color: "$text-neutrals",
172
- minWidth: "230px",
173
- boxSizing: "border-box",
174
- "&:hover": {
175
- border: "1px solid $border-primary-hover",
176
- cursor: "pointer"
177
- }
178
- });
179
- const StyledPickerInputContent = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
180
- display: "flex",
181
- alignItems: "center",
182
- fontSize: "$200",
183
- lineHeight: "24px",
184
- width: "100%",
185
- height: "48px"
65
+ const StyledGroup = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
66
+ position: "relative"
186
67
  });
187
68
  const StyledPicker = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {});
188
69
 
@@ -257,6 +138,24 @@ const StyledClearContent = designSystemStitches.styled(designSystemPrimitive.Pri
257
138
  borderTop: "1px solid $border-neutrals"
258
139
  });
259
140
 
141
+ const StyledButton = designSystemStitches.styled(designSystemPrimitive.Primitive.button, {
142
+ padding: "0",
143
+ backgroundColor: "$transparent",
144
+ border: "none",
145
+ cursor: "pointer",
146
+ color: "$text-neutrals",
147
+ "&[disabled]": {
148
+ cursor: "not-allowed"
149
+ }
150
+ });
151
+
152
+ const Button = React__default["default"].forwardRef((props, forwardRef) => {
153
+ const { buttonProps } = reactAria.useButton(props, forwardRef);
154
+ const { focusProps } = reactAria.useFocusRing();
155
+ const { children } = props;
156
+ return /* @__PURE__ */ jsxRuntime.jsx(StyledButton, { ...reactAria.mergeProps(buttonProps, focusProps), ref: forwardRef, children });
157
+ });
158
+
260
159
  const StyledHeaderTitle = designSystemStitches.styled(designSystemFlex.Flex, {
261
160
  justifyContent: "center",
262
161
  flex: "3",
@@ -432,6 +331,125 @@ const Grid = React__default["default"].forwardRef(
432
331
  }
433
332
  );
434
333
 
334
+ const StyledPlaceholder = designSystemStitches.styled(designSystemPrimitive.Primitive.span, {
335
+ ...designSystemBaseTextField.textFieldStyles.base.placeholder,
336
+ padding: "0 $50"
337
+ });
338
+ const StyledValue = designSystemStitches.styled(designSystemPrimitive.Primitive.span, {
339
+ padding: "0 $50"
340
+ });
341
+ const StyledTriggerContainer = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
342
+ position: "relative"
343
+ });
344
+ const StyledTrigger = designSystemStitches.styled(designSystemPrimitive.Primitive.button, {
345
+ all: "unset",
346
+ display: "inline-flex",
347
+ gap: "$50",
348
+ justifyContent: "space-between",
349
+ alignItems: "center",
350
+ height: "$10",
351
+ padding: "0 $100",
352
+ minWidth: "230px",
353
+ ...designSystemBaseTextField.textFieldStyles.variants.idle,
354
+ "& svg": {
355
+ color: "$text-neutrals-subtle",
356
+ square: "22px"
357
+ },
358
+ _hover: designSystemBaseTextField.textFieldStyles.variants.hovered,
359
+ ...designSystemStyles.focus.css(designSystemBaseTextField.textFieldStyles.variants.focused),
360
+ variants: {
361
+ withClearButton: {
362
+ true: {
363
+ paddingRight: "calc($100 + $400)"
364
+ // initial left padding + clear button width + gap
365
+ }
366
+ }
367
+ }
368
+ });
369
+ const StyledCustomTrigger = designSystemStitches.styled(designSystemPrimitive.Primitive.button, {
370
+ width: "100%",
371
+ height: "unset",
372
+ padding: "0",
373
+ backgroundColor: "$transparent",
374
+ border: "none",
375
+ cursor: "pointer"
376
+ });
377
+
378
+ const StyledClearButton = designSystemStitches.styled(designSystemBaseButton.BaseButton, {
379
+ position: "absolute",
380
+ top: 0,
381
+ bottom: 0,
382
+ right: "calc($100 + 1px)",
383
+ // to compensate border width
384
+ margin: "auto",
385
+ ...designSystemBaseTextField.actionButtonStyles
386
+ });
387
+
388
+ const ClearButton = React__default["default"].forwardRef(({ "aria-label": ariaLabel, label, ...restProps }, forwardRef) => /* @__PURE__ */ jsxRuntime.jsxs(designSystemTooltip.Tooltip, { children: [
389
+ /* @__PURE__ */ jsxRuntime.jsx(designSystemTooltip.Tooltip.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
390
+ StyledClearButton,
391
+ {
392
+ ...restProps,
393
+ ref: forwardRef,
394
+ "aria-label": ariaLabel != null ? ariaLabel : label,
395
+ children: /* @__PURE__ */ jsxRuntime.jsx(designSystemIcons.IconCross, {})
396
+ }
397
+ ) }),
398
+ /* @__PURE__ */ jsxRuntime.jsx(designSystemTooltip.Tooltip.Content, { children: label })
399
+ ] }));
400
+
401
+ function dateToString(value) {
402
+ if (value == null) {
403
+ return void 0;
404
+ }
405
+ if ("start" in value) {
406
+ if (value.start == null || value.end == null) {
407
+ return void 0;
408
+ }
409
+ return "".concat(value.start, " - ").concat(value.end);
410
+ }
411
+ return value.toString();
412
+ }
413
+ const Trigger = React__default["default"].forwardRef(
414
+ ({
415
+ placeholder,
416
+ displayValue,
417
+ stateValue,
418
+ asChild = false,
419
+ clearable = true,
420
+ clearActionLabel,
421
+ onClear,
422
+ ...restProps
423
+ }, forwardRef) => {
424
+ const { buttonProps } = reactAria.useButton(
425
+ restProps,
426
+ forwardRef
427
+ );
428
+ const { children } = restProps;
429
+ if (asChild) {
430
+ return /* @__PURE__ */ jsxRuntime.jsx(StyledCustomTrigger, { ...buttonProps, children });
431
+ }
432
+ const valueToDisplay = displayValue != null ? displayValue : dateToString(stateValue);
433
+ const clearButtonVisible = clearable && clearActionLabel !== void 0 && valueToDisplay != null;
434
+ return /* @__PURE__ */ jsxRuntime.jsxs(StyledTriggerContainer, { children: [
435
+ /* @__PURE__ */ jsxRuntime.jsxs(
436
+ StyledTrigger,
437
+ {
438
+ "data-custom": "",
439
+ ...buttonProps,
440
+ ref: forwardRef,
441
+ withClearButton: clearButtonVisible,
442
+ children: [
443
+ valueToDisplay != null ? /* @__PURE__ */ jsxRuntime.jsx(StyledValue, { children: valueToDisplay }) : /* @__PURE__ */ jsxRuntime.jsx(StyledPlaceholder, { children: placeholder }),
444
+ !clearButtonVisible && /* @__PURE__ */ jsxRuntime.jsx(designSystemIcons.IconCalendarBlank, { weight: "thin" })
445
+ ]
446
+ }
447
+ ),
448
+ clearButtonVisible && /* @__PURE__ */ jsxRuntime.jsx(ClearButton, { label: clearActionLabel, onPress: onClear })
449
+ ] });
450
+ }
451
+ );
452
+
435
453
  const RangePicker = React__default["default"].forwardRef((props, forwardRef) => {
436
454
  const {
437
455
  predefinedRanges,
@@ -441,17 +459,21 @@ const RangePicker = React__default["default"].forwardRef((props, forwardRef) =>
441
459
  clearButtonText,
442
460
  children,
443
461
  defaultOpen,
444
- onClear
462
+ onClear,
463
+ label,
464
+ placeholder,
465
+ displayValue
445
466
  } = props;
446
467
  const state = reactStately.useDateRangePickerState(
447
468
  props
448
469
  );
449
470
  const ref = React.useRef(null);
450
471
  const { locale } = reactAria.useLocale();
451
- const { groupProps, startFieldProps, endFieldProps, buttonProps } = reactAria.useDateRangePicker(
472
+ const { groupProps, labelProps, buttonProps } = reactAria.useDateRangePicker(
452
473
  {
453
474
  ...props,
454
- isOpen: defaultOpen
475
+ isOpen: defaultOpen,
476
+ label
455
477
  },
456
478
  state,
457
479
  ref
@@ -485,21 +507,32 @@ const RangePicker = React__default["default"].forwardRef((props, forwardRef) =>
485
507
  },
486
508
  [rangeState, state]
487
509
  );
488
- const clear = () => {
510
+ const onClearHandler = () => {
489
511
  state.setValue({ start: null, end: null });
490
512
  if (onClear !== void 0) {
491
513
  onClear();
492
514
  state.close();
493
515
  }
494
516
  };
517
+ const clearableTrigger = clearButtonText !== void 0 && onClear !== void 0;
495
518
  return /* @__PURE__ */ jsxRuntime.jsxs(StyledPicker, { ref: forwardRef, children: [
496
- children === void 0 && /* @__PURE__ */ jsxRuntime.jsx(StyledPickerInput, { ...groupProps, ref, children: /* @__PURE__ */ jsxRuntime.jsxs(StyledPickerInputContent, { children: [
497
- /* @__PURE__ */ jsxRuntime.jsx(TextField, { ...startFieldProps }),
498
- /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", children: "\u2013" }),
499
- /* @__PURE__ */ jsxRuntime.jsx(TextField, { ...endFieldProps }),
500
- /* @__PURE__ */ jsxRuntime.jsx(designSystemFlex.Flex, { css: { marginLeft: "auto" }, children: /* @__PURE__ */ jsxRuntime.jsx(FieldButton, { ...buttonProps, children: /* @__PURE__ */ jsxRuntime.jsx(designSystemIcons.IconCalendarBlank, {}) }) })
501
- ] }) }),
502
- children !== null && /* @__PURE__ */ jsxRuntime.jsx("div", { ...groupProps, ref, children: /* @__PURE__ */ jsxRuntime.jsx(FieldButton, { ...buttonProps, customButton: true, children }) }),
519
+ children === void 0 && /* @__PURE__ */ jsxRuntime.jsxs(StyledGroup, { ...groupProps, ref, children: [
520
+ label !== void 0 && // todo refactoring: use Form Field context
521
+ /* @__PURE__ */ jsxRuntime.jsx(designSystemBaseForm.FloatingLabel, { floating: true, ...labelProps, children: label }),
522
+ /* @__PURE__ */ jsxRuntime.jsx(
523
+ Trigger,
524
+ {
525
+ ...buttonProps,
526
+ placeholder,
527
+ displayValue,
528
+ stateValue: state.value,
529
+ clearable: clearableTrigger,
530
+ clearActionLabel: clearableTrigger ? clearButtonText : void 0,
531
+ onClear: clearableTrigger ? onClearHandler : void 0
532
+ }
533
+ )
534
+ ] }),
535
+ children !== void 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { ...groupProps, ref, children: /* @__PURE__ */ jsxRuntime.jsx(Trigger, { ...buttonProps, asChild: true, children }) }),
503
536
  state.isOpen && /* @__PURE__ */ jsxRuntime.jsx(Popover, { triggerRef: ref, state, placement: "bottom start", children: /* @__PURE__ */ jsxRuntime.jsx(StyledBody, { ref: forwardRef, children: /* @__PURE__ */ jsxRuntime.jsxs(StyledBodyContent, { children: [
504
537
  predefinedRanges !== void 0 && /* @__PURE__ */ jsxRuntime.jsx(
505
538
  PredefinedRanges,
@@ -534,7 +567,7 @@ const RangePicker = React__default["default"].forwardRef((props, forwardRef) =>
534
567
  {
535
568
  size: "medium",
536
569
  type: "button",
537
- onClick: clear,
570
+ onClick: onClearHandler,
538
571
  disabled: rangeState.value === null,
539
572
  children: clearButtonText
540
573
  }
@@ -613,27 +646,47 @@ const DatePicker = React__default["default"].forwardRef((props, forwardRef) => {
613
646
  children,
614
647
  clearButtonText,
615
648
  defaultOpen,
616
- onClear
649
+ onClear,
650
+ label,
651
+ placeholder,
652
+ displayValue
617
653
  } = props;
618
654
  const ref = React.useRef(null);
619
655
  const state = reactStately.useDatePickerState(props);
620
- const { groupProps, fieldProps, buttonProps, calendarProps } = reactAria.useDatePicker(
621
- { ...props, isOpen: defaultOpen },
656
+ const { groupProps, buttonProps, calendarProps, labelProps } = reactAria.useDatePicker(
657
+ {
658
+ ...props,
659
+ isOpen: defaultOpen,
660
+ label
661
+ },
622
662
  state,
623
663
  ref
624
664
  );
625
- const clearState = () => {
665
+ const onClearHandler = () => {
626
666
  state.setValue(null);
627
667
  if (onClear !== void 0) {
628
668
  onClear();
629
669
  }
630
670
  };
671
+ const clearableTrigger = clearButtonText !== void 0 && onClear !== void 0;
631
672
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: picker === "single" ? /* @__PURE__ */ jsxRuntime.jsxs(StyledPicker, { ref: forwardRef, children: [
632
- children === void 0 && /* @__PURE__ */ jsxRuntime.jsx(StyledPickerInput, { ...groupProps, ref, children: /* @__PURE__ */ jsxRuntime.jsxs(StyledPickerInputContent, { children: [
633
- /* @__PURE__ */ jsxRuntime.jsx(TextField, { ...fieldProps }),
634
- /* @__PURE__ */ jsxRuntime.jsx(designSystemFlex.Flex, { css: { marginLeft: "auto" }, children: /* @__PURE__ */ jsxRuntime.jsx(FieldButton, { ...buttonProps, children: /* @__PURE__ */ jsxRuntime.jsx(designSystemIcons.IconCalendarBlank, {}) }) })
635
- ] }) }),
636
- children !== void 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { ...groupProps, ref, children: /* @__PURE__ */ jsxRuntime.jsx(FieldButton, { ...buttonProps, customButton: true, children }) }),
673
+ children === void 0 && /* @__PURE__ */ jsxRuntime.jsxs(StyledGroup, { ...groupProps, ref, children: [
674
+ label !== void 0 && // todo refactoring: use Form Field context
675
+ /* @__PURE__ */ jsxRuntime.jsx(designSystemBaseForm.FloatingLabel, { floating: true, ...labelProps, children: label }),
676
+ /* @__PURE__ */ jsxRuntime.jsx(
677
+ Trigger,
678
+ {
679
+ ...buttonProps,
680
+ placeholder,
681
+ displayValue,
682
+ stateValue: state.value,
683
+ clearable: clearableTrigger,
684
+ clearActionLabel: clearableTrigger ? clearButtonText : void 0,
685
+ onClear: clearableTrigger ? onClearHandler : void 0
686
+ }
687
+ )
688
+ ] }),
689
+ children !== void 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { ...groupProps, ref, children: /* @__PURE__ */ jsxRuntime.jsx(Trigger, { ...buttonProps, asChild: true, children }) }),
637
690
  state.isOpen && /* @__PURE__ */ jsxRuntime.jsx(Popover, { triggerRef: ref, state, placement: "bottom start", children: /* @__PURE__ */ jsxRuntime.jsx(
638
691
  DatePickerBody,
639
692
  {
@@ -641,7 +694,7 @@ const DatePicker = React__default["default"].forwardRef((props, forwardRef) => {
641
694
  defaultValue,
642
695
  predefinedRanges,
643
696
  visibleMonths,
644
- onClear: onClear !== void 0 ? clearState : void 0,
697
+ onClear: onClear !== void 0 ? onClearHandler : void 0,
645
698
  minDate,
646
699
  maxDate,
647
700
  clearButtonText: onClear !== void 0 ? clearButtonText : void 0,
@@ -656,7 +709,7 @@ const DatePicker = React__default["default"].forwardRef((props, forwardRef) => {
656
709
  defaultValue,
657
710
  predefinedRanges,
658
711
  visibleMonths,
659
- onClear: onClear !== void 0 ? clearState : void 0,
712
+ onClear: onClear !== void 0 ? onClearHandler : void 0,
660
713
  minDate,
661
714
  maxDate,
662
715
  clearButtonText: onClear !== void 0 ? clearButtonText : void 0