@khanacademy/wonder-blocks-date-picker 1.2.6 → 2.0.0
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 +111 -0
- package/dist/es/index.css +88 -0
- package/dist/es/index.css.map +1 -0
- package/dist/es/index.js +11 -7
- package/dist/index.css +88 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +10 -6
- package/package.json +17 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,116 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-date-picker
|
|
2
2
|
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 647e025: **Breaking:** this package now styles its components with CSS Modules instead
|
|
8
|
+
of Aphrodite (WB-2120), and its components render unstyled unless its CSS is
|
|
9
|
+
loaded. To set it up:
|
|
10
|
+
|
|
11
|
+
- **Load the CSS.** The JS entry imports `dist/index.css` as a side effect, and
|
|
12
|
+
`"sideEffects": ["**/*.css"]` keeps bundlers from dropping it, so standard
|
|
13
|
+
webpack, Vite and Next.js setups need no change. Builds that can't process
|
|
14
|
+
CSS imports (some SSR or Jest setups) need a CSS loader or mock. The
|
|
15
|
+
stylesheet is also exported as `./css` for apps that load it explicitly.
|
|
16
|
+
- **Declare the cascade layer order** before any Wonder Blocks CSS:
|
|
17
|
+
`@layer reset, shared, shared.base, shared.reset, legacy;`. The component
|
|
18
|
+
rules live in `@layer shared`, so unlayered app CSS now beats them
|
|
19
|
+
regardless of specificity. Overrides passed through `style` / `styles`
|
|
20
|
+
props still go through Aphrodite and keep winning.
|
|
21
|
+
|
|
22
|
+
`filters`, `icon` and `tabs` also gain an `exports` map, so deep imports such
|
|
23
|
+
as `@khanacademy/wonder-blocks-icon/dist/...` no longer resolve. Import from
|
|
24
|
+
the package root or `./css` instead.
|
|
25
|
+
|
|
26
|
+
See the package's other changesets for the precedence edge cases that change
|
|
27
|
+
behavior, and the "Get Started / CSS setup" guide in Storybook.
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- b899214: Migrate `DatePicker` from Aphrodite to CSS Modules (WB-2335, CSS Modules Phase
|
|
32
|
+
5 / Wave G). The public component API is unchanged: same props, DOM structure,
|
|
33
|
+
and `style` override.
|
|
34
|
+
|
|
35
|
+
- The input row, text field and calendar-button styles now live in
|
|
36
|
+
`date-picker-input.module.css`; the footer and calendar day-button styles in
|
|
37
|
+
`date-picker.module.css`.
|
|
38
|
+
- The calendar day buttons' `:focus-visible` ring (WB-2432) is now a CSS
|
|
39
|
+
Modules class, added alongside react-day-picker's own class through its
|
|
40
|
+
`classNames` prop. It replaces the `StyleSheet.create` / `css()` pair and
|
|
41
|
+
uses the shared `--wb-focus-visible` CSS mixin.
|
|
42
|
+
- Rules that override `View`, `TextField` or `IconButton` are nested under a
|
|
43
|
+
marker class (the input container and the calendar wrapper), so they win on
|
|
44
|
+
specificity rather than stylesheet load order. The calendar wrapper `View`
|
|
45
|
+
gains that marker class; it has no styles of its own.
|
|
46
|
+
- The package now ships `dist/index.css` (auto side-effect import), exposes it
|
|
47
|
+
via the new `@khanacademy/wonder-blocks-date-picker/css` subpath, and marks
|
|
48
|
+
`**/*.css` as `sideEffects`. `aphrodite` is dropped from `peerDependencies`
|
|
49
|
+
(the package no longer imports it).
|
|
50
|
+
|
|
51
|
+
### Patch Changes
|
|
52
|
+
|
|
53
|
+
- 9652f57: Load each package's CSS after the CSS of the Wonder Blocks packages it depends
|
|
54
|
+
on. The published JS imported its own `index.css` before its dependencies, so
|
|
55
|
+
bundlers emitted, for example, Button's CSS before Typography's. Both sit in
|
|
56
|
+
`@layer shared` with single-class selectors, so the later `BodyText` rule won and
|
|
57
|
+
Button labels lost their own `font-weight`, `line-height` and `font-size`. The CSS
|
|
58
|
+
import now comes after the dependency imports, matching the source order that
|
|
59
|
+
Storybook already uses.
|
|
60
|
+
- f52e4cd: List the `types` condition first in the `.` export of the package.json (where it wasn't already), so TypeScript picks it before `import`/`require`. Make the `./css` export conditional: `import` now resolves to `dist/es/index.css`, the copy the ESM entry already loads, so importing `./css` alongside the components no longer loads the CSS twice. `require` still resolves to `dist/index.css`.
|
|
61
|
+
- b66b7b7: Extend `processStyleList` to accept CSS Module class names (WB-2325, CSS
|
|
62
|
+
Modules Phase 1).
|
|
63
|
+
|
|
64
|
+
- `StyleType` is widened to also accept `string` (and nested arrays of
|
|
65
|
+
strings). Existing `CSSProperties` / falsy / nested-array values continue
|
|
66
|
+
to work unchanged.
|
|
67
|
+
- `processStyleList` now sorts each leaf into one of three buckets:
|
|
68
|
+
Aphrodite stylesheets (detected via the existing `_definition` symbol)
|
|
69
|
+
→ `css(...)`; plain strings → appended to `className`; plain objects
|
|
70
|
+
without `_definition` → forwarded as inline `style`. Non-string,
|
|
71
|
+
non-object truthy leaves are silently ignored.
|
|
72
|
+
|
|
73
|
+
The Cell / DatePicker / Modal patches are call-site fixes for latent
|
|
74
|
+
spread-of-`StyleType` bugs that the widened union now flags at type-check
|
|
75
|
+
time. Behavior is preserved or improved (no more accidental `{0: 'f',
|
|
76
|
+
1: 'o', ...}` results when a non-object slips into a spread).
|
|
77
|
+
|
|
78
|
+
- Updated dependencies [0c6d97d]
|
|
79
|
+
- Updated dependencies [185dbbc]
|
|
80
|
+
- Updated dependencies [0b6c478]
|
|
81
|
+
- Updated dependencies [9652f57]
|
|
82
|
+
- Updated dependencies [aa5a8e1]
|
|
83
|
+
- Updated dependencies [f52e4cd]
|
|
84
|
+
- Updated dependencies [f52e4cd]
|
|
85
|
+
- Updated dependencies [647e025]
|
|
86
|
+
- Updated dependencies [b66b7b7]
|
|
87
|
+
- Updated dependencies [b43cd7b]
|
|
88
|
+
- Updated dependencies [3e08381]
|
|
89
|
+
- Updated dependencies [dbb8f0f]
|
|
90
|
+
- Updated dependencies [7afdf5c]
|
|
91
|
+
- Updated dependencies [378e580]
|
|
92
|
+
- Updated dependencies [64734d2]
|
|
93
|
+
- Updated dependencies [6eb8e6d]
|
|
94
|
+
- Updated dependencies [ad52f4b]
|
|
95
|
+
- Updated dependencies [9c09ca7]
|
|
96
|
+
- Updated dependencies [a1002be]
|
|
97
|
+
- Updated dependencies [e4f0a12]
|
|
98
|
+
- Updated dependencies [e4f0a12]
|
|
99
|
+
- Updated dependencies [415b002]
|
|
100
|
+
- @khanacademy/wonder-blocks-tokens@18.3.0
|
|
101
|
+
- @khanacademy/wonder-blocks-modal@9.0.0
|
|
102
|
+
- @khanacademy/wonder-blocks-core@13.0.0
|
|
103
|
+
- @khanacademy/wonder-blocks-form@8.0.0
|
|
104
|
+
- @khanacademy/wonder-blocks-icon-button@13.0.0
|
|
105
|
+
- @khanacademy/wonder-blocks-styles@1.0.0
|
|
106
|
+
|
|
107
|
+
## 1.2.7
|
|
108
|
+
|
|
109
|
+
### Patch Changes
|
|
110
|
+
|
|
111
|
+
- @khanacademy/wonder-blocks-form@7.7.9
|
|
112
|
+
- @khanacademy/wonder-blocks-modal@8.10.7
|
|
113
|
+
|
|
3
114
|
## 1.2.6
|
|
4
115
|
|
|
5
116
|
### Patch Changes
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
@layer shared {/**
|
|
2
|
+
* DatePickerInput styles.
|
|
3
|
+
*
|
|
4
|
+
* Every rule is nested inside `.root`, the marker class on the container
|
|
5
|
+
* `View`, which carries no declarations of its own. The container is a
|
|
6
|
+
* `View`, the text field a `TextField` and the button an `IconButton`, and
|
|
7
|
+
* each ships rules in the same `@layer shared` that set properties overridden
|
|
8
|
+
* below (`flex-direction`, `align-items`, `inline-size`, `padding-inline`).
|
|
9
|
+
* The bundle loads this package's CSS before its dependencies', so the
|
|
10
|
+
* compound selectors make these win on specificity rather than load order.
|
|
11
|
+
*
|
|
12
|
+
* The build wraps every rule in `@layer shared { … }`.
|
|
13
|
+
*/.wb-date-picker-input-root-6e24f715 {
|
|
14
|
+
&.wb-date-picker-input-container-6e24f715 {
|
|
15
|
+
align-items: center;
|
|
16
|
+
flex-direction: row;
|
|
17
|
+
justify-content: stretch;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* Match form field left padding. Inset the button's own hit target (not
|
|
21
|
+
* just its icon glyph) by this amount, so the button's edges -- which
|
|
22
|
+
* become visible on hover/focus/press -- line up with the text field's
|
|
23
|
+
* left inline padding at every interaction state.
|
|
24
|
+
* `--wb-sizing-size_160` matches the TextField theme. */
|
|
25
|
+
& .wb-date-picker-input-icon-6e24f715 {
|
|
26
|
+
margin: 0;
|
|
27
|
+
position: absolute;
|
|
28
|
+
inset-inline-end: var(--wb-sizing-size_160);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
& .wb-date-picker-input-textField-6e24f715 {
|
|
32
|
+
inline-size: 100%;
|
|
33
|
+
|
|
34
|
+
/* Start: match the text field's left padding. End: reserve enough
|
|
35
|
+
* padding that typed text never runs under the calendar button --
|
|
36
|
+
* field padding + the IconButton size="small" hit target
|
|
37
|
+
* (`--wb-sizing-size_320`) + half the field padding. */
|
|
38
|
+
padding-inline: var(--wb-sizing-size_160)
|
|
39
|
+
calc(
|
|
40
|
+
var(--wb-sizing-size_160) + var(--wb-sizing-size_320) +
|
|
41
|
+
var(--wb-sizing-size_160) / 2
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@layer shared {/**
|
|
48
|
+
* DatePicker calendar overlay styles.
|
|
49
|
+
*
|
|
50
|
+
* `.overlayRoot` is a marker class on the `View` that wraps the calendar and
|
|
51
|
+
* footer; it carries no declarations of its own. The footer is a `View`, whose
|
|
52
|
+
* own rule (same `@layer shared`) sets `margin`, and the bundle loads this
|
|
53
|
+
* package's CSS before core's, so nesting the footer rule under the marker
|
|
54
|
+
* makes it win on specificity rather than load order.
|
|
55
|
+
*
|
|
56
|
+
* The build wraps every rule in `@layer shared { … }`.
|
|
57
|
+
*//*
|
|
58
|
+
* Cross-package focus-visible mixin.
|
|
59
|
+
*
|
|
60
|
+
* Authors include the mixin via:
|
|
61
|
+
*
|
|
62
|
+
* @import "@khanacademy/wonder-blocks-styles/focus-styles.css";
|
|
63
|
+
*
|
|
64
|
+
* .my-component:focus-visible {
|
|
65
|
+
* @apply --wb-focus-visible;
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* postcss-import resolves the @import through the workspace and
|
|
69
|
+
* @csstools/postcss-mixins expands the @apply at build time
|
|
70
|
+
* (CSS Mixins Level 1 syntax — note the leading `--` on the name).
|
|
71
|
+
*/.wb-date-picker-overlayRoot-325d8b69 {
|
|
72
|
+
& .wb-date-picker-footer-325d8b69 {
|
|
73
|
+
margin: var(--wb-sizing-size_120);
|
|
74
|
+
margin-block-start: 0;
|
|
75
|
+
}
|
|
76
|
+
}/* React Day Picker's own day buttons don't use the Wonder Blocks focus style,
|
|
77
|
+
* so we add this as an extra class alongside the default one. React Day
|
|
78
|
+
* Picker's stylesheet is unlayered, but it never sets `outline` or
|
|
79
|
+
* `box-shadow` on day buttons, so this layered rule doesn't compete with it. */.wb-date-picker-dayButton-325d8b69:focus-visible {
|
|
80
|
+
box-shadow: 0 0 0 var(--wb-border-width-medium)
|
|
81
|
+
var(--wb-semanticColor-focus-inner);
|
|
82
|
+
outline: var(--wb-border-width-medium) solid
|
|
83
|
+
var(--wb-semanticColor-focus-outer);
|
|
84
|
+
outline-offset: var(--wb-border-width-medium);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/*# sourceMappingURL=index.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["<no source>","../../src/components/date-picker-input.module.css","../../src/components/date-picker.module.css","../../../wonder-blocks-styles/src/styles/focus-styles.css"],"names":[],"mappings":"AAAA,eCAA;;;;;;;;;;;;EAYE,CAEF;IACI;QACI,mBAAmB;QACnB,mBAAmB;QACnB,wBAAwB;IAC5B;;IAEA;;;;4DAIwD;IACxD;QACI,SAAS;QACT,kBAAkB;QAClB,2CAA2C;IAC/C;;IAEA;QACI,iBAAiB;;QAEjB;;;+DAGuD;QACvD;;;;aAIK;IACT;AACJ;CD7CA;;AAAA,eEAA;;;;;;;;;;EAUE,CCVF;;;;;;;;;;;;;;EAcE,CDAF;IACI;QACI,iCAAiC;QACjC,qBAAqB;IACzB;AACJ,CAEA;;;+EAG+E,CAC/E;ICTI;2CACuC;IACvC;2CACuC;IACvC,6CAA6C;ADOjD;CF3BA","file":"index.css","sourcesContent":[null,"/**\n * DatePickerInput styles.\n *\n * Every rule is nested inside `.root`, the marker class on the container\n * `View`, which carries no declarations of its own. The container is a\n * `View`, the text field a `TextField` and the button an `IconButton`, and\n * each ships rules in the same `@layer shared` that set properties overridden\n * below (`flex-direction`, `align-items`, `inline-size`, `padding-inline`).\n * The bundle loads this package's CSS before its dependencies', so the\n * compound selectors make these win on specificity rather than load order.\n *\n * The build wraps every rule in `@layer shared { … }`.\n */\n\n.root {\n &.container {\n align-items: center;\n flex-direction: row;\n justify-content: stretch;\n }\n\n /* Match form field left padding. Inset the button's own hit target (not\n * just its icon glyph) by this amount, so the button's edges -- which\n * become visible on hover/focus/press -- line up with the text field's\n * left inline padding at every interaction state.\n * `--wb-sizing-size_160` matches the TextField theme. */\n & .icon {\n margin: 0;\n position: absolute;\n inset-inline-end: var(--wb-sizing-size_160);\n }\n\n & .textField {\n inline-size: 100%;\n\n /* Start: match the text field's left padding. End: reserve enough\n * padding that typed text never runs under the calendar button --\n * field padding + the IconButton size=\"small\" hit target\n * (`--wb-sizing-size_320`) + half the field padding. */\n padding-inline: var(--wb-sizing-size_160)\n calc(\n var(--wb-sizing-size_160) + var(--wb-sizing-size_320) +\n var(--wb-sizing-size_160) / 2\n );\n }\n}\n","/**\n * DatePicker calendar overlay styles.\n *\n * `.overlayRoot` is a marker class on the `View` that wraps the calendar and\n * footer; it carries no declarations of its own. The footer is a `View`, whose\n * own rule (same `@layer shared`) sets `margin`, and the bundle loads this\n * package's CSS before core's, so nesting the footer rule under the marker\n * makes it win on specificity rather than load order.\n *\n * The build wraps every rule in `@layer shared { … }`.\n */\n\n@import \"@khanacademy/wonder-blocks-styles/focus-styles.css\";\n\n.overlayRoot {\n & .footer {\n margin: var(--wb-sizing-size_120);\n margin-block-start: 0;\n }\n}\n\n/* React Day Picker's own day buttons don't use the Wonder Blocks focus style,\n * so we add this as an extra class alongside the default one. React Day\n * Picker's stylesheet is unlayered, but it never sets `outline` or\n * `box-shadow` on day buttons, so this layered rule doesn't compete with it. */\n.dayButton:focus-visible {\n @apply --wb-focus-visible;\n}\n","/*\n * Cross-package focus-visible mixin.\n *\n * Authors include the mixin via:\n *\n * @import \"@khanacademy/wonder-blocks-styles/focus-styles.css\";\n *\n * .my-component:focus-visible {\n * @apply --wb-focus-visible;\n * }\n *\n * postcss-import resolves the @import through the workspace and\n * @csstools/postcss-mixins expands the @apply at build time\n * (CSS Mixins Level 1 syntax — note the leading `--` on the name).\n */\n@mixin --wb-focus-visible() {\n box-shadow: 0 0 0 var(--wb-border-width-medium)\n var(--wb-semanticColor-focus-inner);\n outline: var(--wb-border-width-medium) solid\n var(--wb-semanticColor-focus-outer);\n outline-offset: var(--wb-border-width-medium);\n}\n"]}
|
package/dist/es/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { StyleSheet, css } from 'aphrodite';
|
|
3
2
|
import { Temporal } from 'temporal-polyfill';
|
|
4
3
|
import * as React from 'react';
|
|
5
4
|
import { UI, getDefaultClassNames, DayPicker } from 'react-day-picker';
|
|
6
5
|
import { enUS } from 'react-day-picker/locale';
|
|
7
6
|
import { useDirectionDetection, useOnMountEffect, View, findFocusableNodes } from '@khanacademy/wonder-blocks-core';
|
|
8
|
-
import {
|
|
9
|
-
import { focusStyles } from '@khanacademy/wonder-blocks-styles';
|
|
7
|
+
import { semanticColor, border, boxShadow, font, sizing } from '@khanacademy/wonder-blocks-tokens';
|
|
10
8
|
import { useWonderBlocksI18n } from '@khanacademy/wonder-blocks-config';
|
|
11
9
|
import { TextField } from '@khanacademy/wonder-blocks-form';
|
|
12
10
|
import IconButton from '@khanacademy/wonder-blocks-icon-button';
|
|
@@ -50,12 +48,18 @@ function getDateSegments(value,formatString,locale){if(!value){return null}if(fo
|
|
|
50
48
|
|
|
51
49
|
function useDateSegmentArrowKeys({value,dateFormat,locale,parseDate,handleChange,innerRef}){const pendingSelectionRef=React.useRef(null);const isRtl=useDirectionDetection(innerRef)==="rtl";React.useEffect(()=>{if(pendingSelectionRef.current&&innerRef.current){const[start,end]=pendingSelectionRef.current;innerRef.current.setSelectionRange(start,end);pendingSelectionRef.current=null;}},[value,innerRef]);return React.useCallback(e=>{const key=e.key;const isVerticalKey=key==="ArrowUp"||key==="ArrowDown";const isHorizontalKey=key==="ArrowLeft"||key==="ArrowRight";if(!isVerticalKey&&!isHorizontalKey){return false}if(!value){return false}const segments=getDateSegments(value,dateFormat,locale);if(!segments){return false}const offset=e.currentTarget.selectionStart??0;const segment=findSegmentAtOffset(segments,offset);if(!segment){return false}if(isHorizontalKey){const movesToNextSegment=isRtl?key==="ArrowLeft":key==="ArrowRight";const currentIndex=segments.indexOf(segment);const targetSegment=segments[currentIndex+(movesToNextSegment?1:-1)]??segment;e.preventDefault();innerRef.current?.setSelectionRange(targetSegment.start,targetSegment.end);return true}if(!parseDate){return false}const jsDate=parseDate(value,dateFormat,locale);if(!jsDate){return false}const currentDate=TemporalLocaleUtils.jsDateToTemporalDate(jsDate);const delta=key==="ArrowUp"?1:-1;const adjustedDate=adjustDateSegment(currentDate,segment.type,delta);const newValue=TemporalLocaleUtils.formatDate(adjustedDate,dateFormat,locale);const newSegments=getDateSegments(newValue,dateFormat,locale);const newSegment=newSegments?.find(s=>s.type===segment.type);pendingSelectionRef.current=newSegment?[newSegment.start,newSegment.end]:null;e.preventDefault();handleChange(newValue);return true},[value,dateFormat,locale,parseDate,handleChange,isRtl,innerRef])}
|
|
52
50
|
|
|
53
|
-
|
|
51
|
+
var modules_7c8e65e7={"root":"wb-date-picker-input-root-6e24f715","container":"wb-date-picker-input-container-6e24f715","icon":"wb-date-picker-input-icon-6e24f715","textField":"wb-date-picker-input-textField-6e24f715"};
|
|
52
|
+
|
|
53
|
+
const DatePickerInput=React.forwardRef((props,ref)=>{const{value:propValue,onBlur,onFocus,onKeyDown,onChange,dateFormat,locale=enUSLocaleCode,modifiers,getModifiersForDay,parseDate,placeholder,testId,resetInvalidValueOnBlur=true,["aria-label"]:ariaLabel,expanded,onToggleOverlay,onCalendarButtonKeyDown,calendarButtonAriaLabel,calendarButtonRef,...restProps}=props;const{strings}=useWonderBlocksI18n();const[value,setValue]=React.useState(propValue);const lastPropValueRef=React.useRef(propValue);const keepInvalidTextRef=React.useRef(false);const lastTypedTextFormatValueRef=React.useRef(null);const processModifiers=React.useCallback((date,value)=>{if(!getModifiersForDay||!modifiers){return {}}return getModifiersForDay(date,modifiers).reduce((obj,modifier)=>({...obj,[modifier]:true}),{})},[getModifiersForDay,modifiers]);const updateDate=React.useCallback((date,inputValue)=>{if(onChange){onChange(date,processModifiers(date,inputValue),inputValue||undefined);}},[onChange,processModifiers]);const updateDateAsInvalid=React.useCallback(()=>{if(onChange){onChange(null,{});}},[onChange]);const processDate=React.useCallback(inputValue=>{if(!inputValue||inputValue.trim()===""){return}if(!parseDate){return}const date=parseDate(inputValue,dateFormat,locale);if(!date){return}return date},[parseDate,dateFormat,locale]);const isValid=React.useCallback(()=>{const date=processDate(value);if(!date){return false}const modifiersResult=processModifiers(date,value);if(modifiersResult.disabled){return false}return true},[value,processDate,processModifiers]);const isTextFormat=TemporalLocaleUtils.isTextFormatDate(dateFormat);React.useEffect(()=>{const propValueChanged=lastPropValueRef.current!==propValue;lastPropValueRef.current=propValue;if(propValueChanged){const safeProp=propValue??"";const safeValue=value??"";const isLastTypedValue=lastTypedTextFormatValueRef.current!==null&&value===lastTypedTextFormatValueRef.current;const bothHaveContent=safeValue!==""&&safeProp!=="";const oneIsPrefixOfOther=safeProp.startsWith(safeValue)||safeValue.startsWith(safeProp);const skipSyncUserTyping=isTextFormat&&propValue!==value&&(isLastTypedValue||bothHaveContent&&oneIsPrefixOfOther);if(keepInvalidTextRef.current&&(!propValue||propValue.trim()==="")){keepInvalidTextRef.current=false;}else if(skipSyncUserTyping){return}else if(propValue===value||(propValue??"")===(value??"")){keepInvalidTextRef.current=false;lastTypedTextFormatValueRef.current=null;return}else {setValue(propValue);keepInvalidTextRef.current=false;lastTypedTextFormatValueRef.current=null;}}},[propValue,isTextFormat,value]);useOnMountEffect(()=>{const skipValidation=dateFormat==="LL"&&propValue;if(!skipValidation&&!isValid()){updateDateAsInvalid();}});const handleFocus=e=>{if(onFocus){onFocus(e);}};const pendingValidationRef=React.useRef(false);const validateInput=React.useCallback(()=>{lastTypedTextFormatValueRef.current=null;const date=processDate(value);if(date){const modifiersResult=processModifiers(date,value);if(!modifiersResult.disabled){updateDate(date,value);}else {if(!resetInvalidValueOnBlur){keepInvalidTextRef.current=true;updateDate(date,value);}else {setValue(propValue);}}}else if(value&&value.trim()!==""){if(!resetInvalidValueOnBlur){keepInvalidTextRef.current=true;updateDateAsInvalid();}else {setValue(propValue);}}else {setValue(propValue);}},[value,processDate,processModifiers,resetInvalidValueOnBlur,propValue,updateDate,updateDateAsInvalid]);const handleBlur=e=>{const movingToCalendar=e.relatedTarget instanceof HTMLElement&&e.relatedTarget.closest('[data-testid="date-picker-overlay"]')!==null;if(movingToCalendar){pendingValidationRef.current=true;if(onBlur){onBlur(e);}return}validateInput();if(onBlur){onBlur(e);}};const innerRef=React.useRef(null);const handleChange=newValue=>{setValue(newValue);const date=processDate(newValue);if(date){const modifiersResult=processModifiers(date,newValue);if(isTextFormat){lastTypedTextFormatValueRef.current=newValue;}if(!modifiersResult.disabled){updateDate(date,newValue);}else if(!resetInvalidValueOnBlur){keepInvalidTextRef.current=true;updateDate(date,newValue);}else {updateDate(date,newValue);}}else if(!resetInvalidValueOnBlur&&newValue&&newValue.trim()!==""){keepInvalidTextRef.current=true;updateDateAsInvalid();}};const handleSegmentKeyDown=useDateSegmentArrowKeys({value,dateFormat,locale,parseDate,handleChange,innerRef});const handleInputKeyDown=e=>{if(!expanded&&handleSegmentKeyDown(e)){return}onKeyDown?.(e);};React.useImperativeHandle(ref,()=>{const inputElement=innerRef.current;if(!inputElement){return null}inputElement.validateInput=()=>{pendingValidationRef.current=false;validateInput();};return inputElement});return jsxs(View,{style:[modules_7c8e65e7.root,modules_7c8e65e7.container],children:[jsx(TextField,{ref:innerRef,...restProps,onBlur:handleBlur,onFocus:handleFocus,onKeyDown:handleInputKeyDown,onChange:handleChange,disabled:restProps.disabled,placeholder:placeholder,value:value??"",testId:testId,"aria-label":ariaLabel,autoComplete:"off",type:"text",style:modules_7c8e65e7.textField}),jsx(IconButton,{ref:calendarButtonRef,icon:calendarIcon,size:"small",kind:"tertiary",actionType:"neutral",disabled:restProps.disabled,"aria-label":calendarButtonAriaLabel||strings.iconAltToggleCalendar,"aria-expanded":expanded,"aria-haspopup":"grid",onClick:()=>onToggleOverlay(),onKeyDown:onCalendarButtonKeyDown,style:modules_7c8e65e7.icon})]})});var DatePickerInput$1 = DatePickerInput;
|
|
54
54
|
|
|
55
55
|
function FocusManager(props){const{children,referenceElement,onStartFocused,onEndFocused}=props;const rootNodeRef=React.useRef(null);const focusableElementsRef=React.useRef([]);const focusableElementsInsideRef=React.useRef([]);const nextFocusableElementRef=React.useRef(null);const getFocusableElements=React.useCallback(()=>{return findFocusableNodes(document)},[]);const getReferenceIndex=React.useCallback(()=>{if(!referenceElement){return -1}return focusableElementsRef.current.indexOf(referenceElement)},[referenceElement]);const getNextFocusableElement=React.useCallback(()=>{const referenceIndex=getReferenceIndex();if(referenceIndex>=0){const nextElementIndex=referenceIndex<focusableElementsRef.current.length-1?referenceIndex+1:0;return focusableElementsRef.current[nextElementIndex]}return undefined},[getReferenceIndex]);React.useEffect(()=>{focusableElementsRef.current=getFocusableElements();nextFocusableElementRef.current=getNextFocusableElement();const handleKeydownReferenceElement=e=>{if(e.key==="Tab"&&!e.shiftKey){if(rootNodeRef.current){focusableElementsInsideRef.current=findFocusableNodes(rootNodeRef.current);}if(focusableElementsInsideRef.current.length>0){e.preventDefault();focusableElementsInsideRef.current[0]?.focus();}}};const handleKeydownNextFocusableElement=e=>{if(e.key==="Tab"&&e.shiftKey){if(rootNodeRef.current){focusableElementsInsideRef.current=findFocusableNodes(rootNodeRef.current);}if(focusableElementsInsideRef.current.length>0){e.preventDefault();const lastIndex=focusableElementsInsideRef.current.length-1;focusableElementsInsideRef.current[lastIndex]?.focus();}}};if(referenceElement){referenceElement.addEventListener("keydown",handleKeydownReferenceElement,true);}if(nextFocusableElementRef.current){nextFocusableElementRef.current.addEventListener("keydown",handleKeydownNextFocusableElement,true);}return ()=>{if(referenceElement){referenceElement.removeEventListener("keydown",handleKeydownReferenceElement,true);}if(nextFocusableElementRef.current){nextFocusableElementRef.current.removeEventListener("keydown",handleKeydownNextFocusableElement,true);}}},[referenceElement,getNextFocusableElement,getFocusableElements]);const setComponentRootNode=React.useCallback(node=>{if(!node){return}rootNodeRef.current=node;focusableElementsInsideRef.current=findFocusableNodes(node);},[]);const handleFocusPreviousFocusableElement=React.useCallback(()=>{if(referenceElement){referenceElement.focus();}if(onStartFocused){onStartFocused();}},[referenceElement,onStartFocused]);const handleFocusNextFocusableElement=React.useCallback(()=>{if(nextFocusableElementRef.current){nextFocusableElementRef.current.focus();}if(onEndFocused){onEndFocused();}},[onEndFocused]);return jsxs(React.Fragment,{children:[jsx("div",{tabIndex:0,"data-testid":"focus-sentinel-prev",onFocus:handleFocusPreviousFocusableElement,style:{position:"fixed"}}),jsx("div",{"data-testid":"date-picker-overlay",ref:setComponentRootNode,children:children}),jsx("div",{tabIndex:0,"data-testid":"focus-sentinel-next",onFocus:handleFocusNextFocusableElement,style:{position:"fixed"}})]})}
|
|
56
56
|
|
|
57
|
-
const DEFAULT_STYLE={background:semanticColor.core.background.base.default,borderRadius:border.radius.radius_040,border:`solid ${border.width.thin} ${semanticColor.core.border.neutral.subtle}`,boxShadow:boxShadow.mid};const BASE_CONTAINER_STYLES={fontFamily:font.family.sans,padding:sizing.size_100};const OUT_OF_BOUNDARIES_STYLES={visibility:"hidden"};const DatePickerOverlay=({children,referenceElement,focusReferenceElement,onClose,dir="ltr",style=DEFAULT_STYLE,calendarGridRegionAriaLabel})=>{const{strings}=useWonderBlocksI18n();if(!referenceElement){return null}const placement=dir==="rtl"?"bottom-end":"bottom-start";const modalHost=maybeGetPortalMountedModalHostElement(referenceElement)||document.querySelector("body");if(!modalHost){return null}return createPortal(jsx(FocusManager,{referenceElement:focusReferenceElement??referenceElement,onEndFocused:onClose,children:jsx(Popper,{referenceElement:referenceElement,placement:placement,strategy:"fixed",modifiers:[{name:"preventOverflow",options:{rootBoundary:"viewport"}}],children:({placement,ref,style:popperStyle,isReferenceHidden,hasPopperEscaped})=>{const isTestEnvironment=typeof window!=="undefined"&&window.navigator.userAgent.includes("jsdom");const outOfBoundaries=!isTestEnvironment&&(isReferenceHidden||hasPopperEscaped);const combinedStyles={...BASE_CONTAINER_STYLES,...popperStyle,...
|
|
57
|
+
const DEFAULT_STYLE={background:semanticColor.core.background.base.default,borderRadius:border.radius.radius_040,border:`solid ${border.width.thin} ${semanticColor.core.border.neutral.subtle}`,boxShadow:boxShadow.mid};const BASE_CONTAINER_STYLES={fontFamily:font.family.sans,padding:sizing.size_100};const OUT_OF_BOUNDARIES_STYLES={visibility:"hidden"};const DatePickerOverlay=({children,referenceElement,focusReferenceElement,onClose,dir="ltr",style=DEFAULT_STYLE,calendarGridRegionAriaLabel})=>{const{strings}=useWonderBlocksI18n();if(!referenceElement){return null}const placement=dir==="rtl"?"bottom-end":"bottom-start";const modalHost=maybeGetPortalMountedModalHostElement(referenceElement)||document.querySelector("body");if(!modalHost){return null}return createPortal(jsx(FocusManager,{referenceElement:focusReferenceElement??referenceElement,onEndFocused:onClose,children:jsx(Popper,{referenceElement:referenceElement,placement:placement,strategy:"fixed",modifiers:[{name:"preventOverflow",options:{rootBoundary:"viewport"}}],children:({placement,ref,style:popperStyle,isReferenceHidden,hasPopperEscaped})=>{const isTestEnvironment=typeof window!=="undefined"&&window.navigator.userAgent.includes("jsdom");const outOfBoundaries=!isTestEnvironment&&(isReferenceHidden||hasPopperEscaped);const customStyle=style&&typeof style==="object"&&!Array.isArray(style)?style:null;const combinedStyles={...BASE_CONTAINER_STYLES,...popperStyle,...customStyle,...outOfBoundaries&&OUT_OF_BOUNDARIES_STYLES};return jsx("div",{"aria-label":calendarGridRegionAriaLabel||strings.datePickerCalendar,ref:ref,role:"region",style:combinedStyles,"data-placement":placement,children:children})}})}),modalHost)};var DatePickerOverlay$1 = DatePickerOverlay;
|
|
58
|
+
|
|
59
|
+
var modules_ded9cff2={"overlayRoot":"wb-date-picker-overlayRoot-325d8b69","footer":"wb-date-picker-footer-325d8b69","dayButton":"wb-date-picker-dayButton-325d8b69"};
|
|
60
|
+
|
|
61
|
+
const customRootStyle={"--rdp-accent-color":semanticColor.core.border.instructive.default,"--rdp-today-color":semanticColor.core.foreground.instructive.default};const dayPickerClassNames={[UI.DayButton]:`${getDefaultClassNames()[UI.DayButton]} ${modules_ded9cff2.dayButton}`};const DatePicker=props=>{const{locale,updateDate,dateFormat,disabled,id,maxDate,minDate,inputAriaLabel,calendarButtonAriaLabel,calendarGridRegionAriaLabel,placeholder,selectedDate,style,closeOnSelect=true,resetInvalidValueOnBlur=true,footer}=props;const[showOverlay,setShowOverlay]=React.useState(false);const[currentDate,setCurrentDate]=React.useState(selectedDate);const datePickerInputRef=React.useRef(null);const calendarButtonRef=React.useRef(null);const datePickerRef=React.useRef(null);const refWrapper=React.useRef(null);const skipNextOpenRef=React.useRef(false);const movingFocusIntoOverlayRef=React.useRef(false);const{handleEscapeKeyDown}=useEscapeKeyupCapture();const{displayMonth,setDisplayMonth,displayMonthRef,inputDrivenMonthRef,setDisplayMonthAndRefs}=useDisplayMonth({selectedDate});const open=React.useCallback(()=>{if(skipNextOpenRef.current){skipNextOpenRef.current=false;return}if(!disabled){if(selectedDate!=null){const jsDate=TemporalLocaleUtils.temporalDateToJsDate(selectedDate);setDisplayMonthAndRefs(jsDate);}else {displayMonthRef.current=displayMonthRef.current??displayMonth;}setShowOverlay(true);}},[disabled,displayMonth,displayMonthRef,selectedDate,setDisplayMonthAndRefs,skipNextOpenRef]);const{handleInputChange,clearInputDrivenMonth}=useOverlayMonthFromInput({inputDrivenMonthRef,setDisplayMonth,setDisplayMonthAndRefs,setCurrentDate,updateDate,dateFormat,localeCode:locale?.code});const close=React.useCallback(()=>{clearInputDrivenMonth();if(selectedDate!=null){const jsDate=TemporalLocaleUtils.temporalDateToJsDate(selectedDate);setDisplayMonthAndRefs(jsDate);}else {setDisplayMonthAndRefs(null);}setShowOverlay(false);datePickerInputRef.current?.validateInput?.();},[selectedDate,setDisplayMonthAndRefs,clearInputDrivenMonth,datePickerInputRef]);const handleToggleOverlay=React.useCallback(()=>{if(disabled){return}if(showOverlay){close();}else {skipNextOpenRef.current=false;open();}},[disabled,showOverlay,close,open,skipNextOpenRef]);const focusIntoOverlay=React.useCallback(()=>{const overlayRoot=datePickerRef.current;if(!overlayRoot){return}const grid=overlayRoot.querySelector('[role="grid"]');const rovingTarget=grid?.querySelector('[tabindex="0"]');const target=rovingTarget??findFocusableNodes(grid??overlayRoot)[0];if(target){movingFocusIntoOverlayRef.current=true;target.focus();}},[datePickerRef]);useCloseOnOutsideClick({refWrapper,datePickerRef,showOverlay,closeOnSelect,close});useSelectedDateSync({selectedDate,setCurrentDate,setDisplayMonthAndRefs});const computedLocale=locale??enUS;const selectedDateValue=currentDate?TemporalLocaleUtils.temporalDateToJsDate(currentDate):undefined;const modifiers=useDatePickerModifiers({selectedDateValue,minDate,maxDate});const formatDateForInput=useFormatDateForInput({dateFormat,locale:computedLocale});const dir=refWrapper.current?.closest("[dir]")?.getAttribute("dir")||"ltr";const handleMonthChange=React.useCallback(newMonth=>{clearInputDrivenMonth();setDisplayMonthAndRefs(newMonth);},[clearInputDrivenMonth,setDisplayMonthAndRefs]);const isLeavingDropdown=e=>{const dayPickerCalendar=datePickerRef.current;if(!(e.relatedTarget instanceof Node)){return true}if(dayPickerCalendar?.contains(e.relatedTarget)){return false}const calendarButton=calendarButtonRef.current;if(calendarButton?.contains(e.relatedTarget)){return false}return true};const handleInputBlur=e=>{if(movingFocusIntoOverlayRef.current){movingFocusIntoOverlayRef.current=false;return}if(isLeavingDropdown(e)){close();}};const onEscapeCloseOverlay=React.useCallback(()=>{skipNextOpenRef.current=true;close();calendarButtonRef.current?.focus();},[close,skipNextOpenRef]);const handleKeyDown=e=>{if(!showOverlay){return}if(e.key==="Escape"){handleEscapeKeyDown(e,onEscapeCloseOverlay);}if(e.key==="ArrowDown"){e.preventDefault();focusIntoOverlay();}if(e.key==="Enter"){e.preventDefault();if(closeOnSelect){close();}}};const handleCalendarButtonKeyDown=React.useCallback(e=>{if(e.key==="ArrowDown"&&showOverlay){e.preventDefault();focusIntoOverlay();}else if(e.key==="Escape"&&showOverlay){handleEscapeKeyDown(e,onEscapeCloseOverlay);}},[showOverlay,focusIntoOverlay,handleEscapeKeyDown,onEscapeCloseOverlay]);const RootWithEsc=React.useCallback(props=>{const{onKeyDown,rootRef:_,...rest}=props;return jsx("div",{...rest,tabIndex:-1,onKeyDown:e=>{onKeyDown?.(e);if(e.key==="Escape"){handleEscapeKeyDown(e,onEscapeCloseOverlay);}}})},[handleEscapeKeyDown,onEscapeCloseOverlay]);const dayPickerComponents=React.useMemo(()=>({Root:RootWithEsc}),[RootWithEsc]);const handleDayClick=React.useCallback((date,{disabled})=>{if(disabled||!date){return}datePickerInputRef.current?.focus();const wrappedDate=TemporalLocaleUtils.jsDateToTemporalDate(date);setCurrentDate(wrappedDate);const monthDate=new Date(date);clearInputDrivenMonth();setDisplayMonthAndRefs(monthDate);updateDate(wrappedDate);setShowOverlay(!closeOnSelect);},[updateDate,closeOnSelect,setDisplayMonthAndRefs,datePickerInputRef,clearInputDrivenMonth]);const renderInput=inputModifiers=>{const selectedDateAsValue=formatDateForInput(currentDate);return jsx(DatePickerInput$1,{onBlur:handleInputBlur,onChange:handleInputChange,onKeyDown:handleKeyDown,"aria-label":inputAriaLabel,disabled:disabled,id:id,placeholder:placeholder,value:selectedDateAsValue,ref:datePickerInputRef,dateFormat:dateFormat,locale:computedLocale.code,parseDate:TemporalLocaleUtils.parseDateToJsDate,getModifiersForDay:TemporalLocaleUtils.getModifiersForDay,modifiers:inputModifiers,resetInvalidValueOnBlur:resetInvalidValueOnBlur,testId:id&&`${id}-input`,expanded:showOverlay,onToggleOverlay:handleToggleOverlay,onCalendarButtonKeyDown:handleCalendarButtonKeyDown,calendarButtonAriaLabel:calendarButtonAriaLabel,calendarButtonRef:calendarButtonRef})};const maybeRenderFooter=()=>{if(!footer){return null}return jsx(View,{testId:"date-picker-footer",style:modules_ded9cff2.footer,children:footer({close})})};const minDateToShow=minDate&&selectedDateValue?Temporal.PlainDate.compare(minDate,currentDate)<0?TemporalLocaleUtils.temporalDateToJsDate(minDate):selectedDateValue:minDate?TemporalLocaleUtils.temporalDateToJsDate(minDate):undefined;const dayPickerEndMonth=React.useMemo(()=>maxDate?TemporalLocaleUtils.temporalDateToJsDate(maxDate):undefined,[maxDate]);const dayPickerStyles=React.useMemo(()=>({root:{...customRootStyle},nav:{width:"auto"}}),[]);const dayPickerModifiersStyles=React.useMemo(()=>({selected:{fontWeight:font.weight.medium},today:{fontWeight:font.weight.bold}}),[]);const inputDrivenMonth=inputDrivenMonthRef.current;const isInputDriven=inputDrivenMonth!=null;const selectedDateAsJs=selectedDate!=null?TemporalLocaleUtils.temporalDateToJsDate(selectedDate):undefined;const baseMonth=displayMonthRef.current??(showOverlay&&selectedDateAsJs?selectedDateAsJs:undefined)??displayMonth??selectedDateValue??new Date;const firstOfBaseMonth=new Date(baseMonth.getFullYear(),baseMonth.getMonth(),1);const pickerKey=isInputDriven?`input-${inputDrivenMonth.getTime()}`:`picker-${baseMonth.getTime()}`;const inputDrivenMonthMs=inputDrivenMonth?.getTime();const firstOfBaseMonthMs=firstOfBaseMonth.getTime();const dayPickerMonthProps=React.useMemo(()=>{if(isInputDriven&&inputDrivenMonthMs!=null){const d=new Date(inputDrivenMonthMs);return {month:new Date(d.getFullYear(),d.getMonth(),1),onMonthChange:handleMonthChange}}return {defaultMonth:new Date(firstOfBaseMonthMs)}},[isInputDriven,inputDrivenMonthMs,firstOfBaseMonthMs,handleMonthChange]);return jsxs(View,{style:style,ref:refWrapper,children:[renderInput(modifiers),showOverlay&&jsx(DatePickerOverlay$1,{referenceElement:datePickerInputRef.current,focusReferenceElement:calendarButtonRef.current??undefined,onClose:close,dir:dir==="rtl"?"rtl":"ltr",calendarGridRegionAriaLabel:calendarGridRegionAriaLabel,children:jsxs(View,{ref:datePickerRef,style:modules_ded9cff2.overlayRoot,children:[jsx(DayPicker,{mode:"single",selected:selectedDateValue,...dayPickerMonthProps,startMonth:minDateToShow??undefined,endMonth:dayPickerEndMonth,modifiers:modifiers,onDayClick:handleDayClick,components:dayPickerComponents,locale:computedLocale,dir:dir,styles:dayPickerStyles,modifiersStyles:dayPickerModifiersStyles,classNames:dayPickerClassNames},pickerKey),maybeRenderFooter()]})})]})};DatePicker.defaultProps={closeOnSelect:true};var DatePicker$1 = DatePicker;
|
|
58
62
|
|
|
59
|
-
|
|
63
|
+
export { DatePicker$1 as DatePicker, TemporalLocaleUtils };
|
|
60
64
|
|
|
61
|
-
|
|
65
|
+
import "./index.css";
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
@layer shared {/**
|
|
2
|
+
* DatePickerInput styles.
|
|
3
|
+
*
|
|
4
|
+
* Every rule is nested inside `.root`, the marker class on the container
|
|
5
|
+
* `View`, which carries no declarations of its own. The container is a
|
|
6
|
+
* `View`, the text field a `TextField` and the button an `IconButton`, and
|
|
7
|
+
* each ships rules in the same `@layer shared` that set properties overridden
|
|
8
|
+
* below (`flex-direction`, `align-items`, `inline-size`, `padding-inline`).
|
|
9
|
+
* The bundle loads this package's CSS before its dependencies', so the
|
|
10
|
+
* compound selectors make these win on specificity rather than load order.
|
|
11
|
+
*
|
|
12
|
+
* The build wraps every rule in `@layer shared { … }`.
|
|
13
|
+
*/.wb-date-picker-input-root-6e24f715 {
|
|
14
|
+
&.wb-date-picker-input-container-6e24f715 {
|
|
15
|
+
align-items: center;
|
|
16
|
+
flex-direction: row;
|
|
17
|
+
justify-content: stretch;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* Match form field left padding. Inset the button's own hit target (not
|
|
21
|
+
* just its icon glyph) by this amount, so the button's edges -- which
|
|
22
|
+
* become visible on hover/focus/press -- line up with the text field's
|
|
23
|
+
* left inline padding at every interaction state.
|
|
24
|
+
* `--wb-sizing-size_160` matches the TextField theme. */
|
|
25
|
+
& .wb-date-picker-input-icon-6e24f715 {
|
|
26
|
+
margin: 0;
|
|
27
|
+
position: absolute;
|
|
28
|
+
inset-inline-end: var(--wb-sizing-size_160);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
& .wb-date-picker-input-textField-6e24f715 {
|
|
32
|
+
inline-size: 100%;
|
|
33
|
+
|
|
34
|
+
/* Start: match the text field's left padding. End: reserve enough
|
|
35
|
+
* padding that typed text never runs under the calendar button --
|
|
36
|
+
* field padding + the IconButton size="small" hit target
|
|
37
|
+
* (`--wb-sizing-size_320`) + half the field padding. */
|
|
38
|
+
padding-inline: var(--wb-sizing-size_160)
|
|
39
|
+
calc(
|
|
40
|
+
var(--wb-sizing-size_160) + var(--wb-sizing-size_320) +
|
|
41
|
+
var(--wb-sizing-size_160) / 2
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@layer shared {/**
|
|
48
|
+
* DatePicker calendar overlay styles.
|
|
49
|
+
*
|
|
50
|
+
* `.overlayRoot` is a marker class on the `View` that wraps the calendar and
|
|
51
|
+
* footer; it carries no declarations of its own. The footer is a `View`, whose
|
|
52
|
+
* own rule (same `@layer shared`) sets `margin`, and the bundle loads this
|
|
53
|
+
* package's CSS before core's, so nesting the footer rule under the marker
|
|
54
|
+
* makes it win on specificity rather than load order.
|
|
55
|
+
*
|
|
56
|
+
* The build wraps every rule in `@layer shared { … }`.
|
|
57
|
+
*//*
|
|
58
|
+
* Cross-package focus-visible mixin.
|
|
59
|
+
*
|
|
60
|
+
* Authors include the mixin via:
|
|
61
|
+
*
|
|
62
|
+
* @import "@khanacademy/wonder-blocks-styles/focus-styles.css";
|
|
63
|
+
*
|
|
64
|
+
* .my-component:focus-visible {
|
|
65
|
+
* @apply --wb-focus-visible;
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* postcss-import resolves the @import through the workspace and
|
|
69
|
+
* @csstools/postcss-mixins expands the @apply at build time
|
|
70
|
+
* (CSS Mixins Level 1 syntax — note the leading `--` on the name).
|
|
71
|
+
*/.wb-date-picker-overlayRoot-325d8b69 {
|
|
72
|
+
& .wb-date-picker-footer-325d8b69 {
|
|
73
|
+
margin: var(--wb-sizing-size_120);
|
|
74
|
+
margin-block-start: 0;
|
|
75
|
+
}
|
|
76
|
+
}/* React Day Picker's own day buttons don't use the Wonder Blocks focus style,
|
|
77
|
+
* so we add this as an extra class alongside the default one. React Day
|
|
78
|
+
* Picker's stylesheet is unlayered, but it never sets `outline` or
|
|
79
|
+
* `box-shadow` on day buttons, so this layered rule doesn't compete with it. */.wb-date-picker-dayButton-325d8b69:focus-visible {
|
|
80
|
+
box-shadow: 0 0 0 var(--wb-border-width-medium)
|
|
81
|
+
var(--wb-semanticColor-focus-inner);
|
|
82
|
+
outline: var(--wb-border-width-medium) solid
|
|
83
|
+
var(--wb-semanticColor-focus-outer);
|
|
84
|
+
outline-offset: var(--wb-border-width-medium);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/*# sourceMappingURL=index.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["<no source>","../src/components/date-picker-input.module.css","../src/components/date-picker.module.css","../../wonder-blocks-styles/src/styles/focus-styles.css"],"names":[],"mappings":"AAAA,eCAA;;;;;;;;;;;;EAYE,CAEF;IACI;QACI,mBAAmB;QACnB,mBAAmB;QACnB,wBAAwB;IAC5B;;IAEA;;;;4DAIwD;IACxD;QACI,SAAS;QACT,kBAAkB;QAClB,2CAA2C;IAC/C;;IAEA;QACI,iBAAiB;;QAEjB;;;+DAGuD;QACvD;;;;aAIK;IACT;AACJ;CD7CA;;AAAA,eEAA;;;;;;;;;;EAUE,CCVF;;;;;;;;;;;;;;EAcE,CDAF;IACI;QACI,iCAAiC;QACjC,qBAAqB;IACzB;AACJ,CAEA;;;+EAG+E,CAC/E;ICTI;2CACuC;IACvC;2CACuC;IACvC,6CAA6C;ADOjD;CF3BA","file":"index.css","sourcesContent":[null,"/**\n * DatePickerInput styles.\n *\n * Every rule is nested inside `.root`, the marker class on the container\n * `View`, which carries no declarations of its own. The container is a\n * `View`, the text field a `TextField` and the button an `IconButton`, and\n * each ships rules in the same `@layer shared` that set properties overridden\n * below (`flex-direction`, `align-items`, `inline-size`, `padding-inline`).\n * The bundle loads this package's CSS before its dependencies', so the\n * compound selectors make these win on specificity rather than load order.\n *\n * The build wraps every rule in `@layer shared { … }`.\n */\n\n.root {\n &.container {\n align-items: center;\n flex-direction: row;\n justify-content: stretch;\n }\n\n /* Match form field left padding. Inset the button's own hit target (not\n * just its icon glyph) by this amount, so the button's edges -- which\n * become visible on hover/focus/press -- line up with the text field's\n * left inline padding at every interaction state.\n * `--wb-sizing-size_160` matches the TextField theme. */\n & .icon {\n margin: 0;\n position: absolute;\n inset-inline-end: var(--wb-sizing-size_160);\n }\n\n & .textField {\n inline-size: 100%;\n\n /* Start: match the text field's left padding. End: reserve enough\n * padding that typed text never runs under the calendar button --\n * field padding + the IconButton size=\"small\" hit target\n * (`--wb-sizing-size_320`) + half the field padding. */\n padding-inline: var(--wb-sizing-size_160)\n calc(\n var(--wb-sizing-size_160) + var(--wb-sizing-size_320) +\n var(--wb-sizing-size_160) / 2\n );\n }\n}\n","/**\n * DatePicker calendar overlay styles.\n *\n * `.overlayRoot` is a marker class on the `View` that wraps the calendar and\n * footer; it carries no declarations of its own. The footer is a `View`, whose\n * own rule (same `@layer shared`) sets `margin`, and the bundle loads this\n * package's CSS before core's, so nesting the footer rule under the marker\n * makes it win on specificity rather than load order.\n *\n * The build wraps every rule in `@layer shared { … }`.\n */\n\n@import \"@khanacademy/wonder-blocks-styles/focus-styles.css\";\n\n.overlayRoot {\n & .footer {\n margin: var(--wb-sizing-size_120);\n margin-block-start: 0;\n }\n}\n\n/* React Day Picker's own day buttons don't use the Wonder Blocks focus style,\n * so we add this as an extra class alongside the default one. React Day\n * Picker's stylesheet is unlayered, but it never sets `outline` or\n * `box-shadow` on day buttons, so this layered rule doesn't compete with it. */\n.dayButton:focus-visible {\n @apply --wb-focus-visible;\n}\n","/*\n * Cross-package focus-visible mixin.\n *\n * Authors include the mixin via:\n *\n * @import \"@khanacademy/wonder-blocks-styles/focus-styles.css\";\n *\n * .my-component:focus-visible {\n * @apply --wb-focus-visible;\n * }\n *\n * postcss-import resolves the @import through the workspace and\n * @csstools/postcss-mixins expands the @apply at build time\n * (CSS Mixins Level 1 syntax — note the leading `--` on the name).\n */\n@mixin --wb-focus-visible() {\n box-shadow: 0 0 0 var(--wb-border-width-medium)\n var(--wb-semanticColor-focus-inner);\n outline: var(--wb-border-width-medium) solid\n var(--wb-semanticColor-focus-outer);\n outline-offset: var(--wb-border-width-medium);\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -3,14 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
-
var aphrodite = require('aphrodite');
|
|
7
6
|
var temporalPolyfill = require('temporal-polyfill');
|
|
8
7
|
var React = require('react');
|
|
9
8
|
var reactDayPicker = require('react-day-picker');
|
|
10
9
|
var locale = require('react-day-picker/locale');
|
|
11
10
|
var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
|
|
12
11
|
var wonderBlocksTokens = require('@khanacademy/wonder-blocks-tokens');
|
|
13
|
-
var wonderBlocksStyles = require('@khanacademy/wonder-blocks-styles');
|
|
14
12
|
var wonderBlocksConfig = require('@khanacademy/wonder-blocks-config');
|
|
15
13
|
var wonderBlocksForm = require('@khanacademy/wonder-blocks-form');
|
|
16
14
|
var IconButton = require('@khanacademy/wonder-blocks-icon-button');
|
|
@@ -78,13 +76,19 @@ function getDateSegments(value,formatString,locale){if(!value){return null}if(fo
|
|
|
78
76
|
|
|
79
77
|
function useDateSegmentArrowKeys({value,dateFormat,locale,parseDate,handleChange,innerRef}){const pendingSelectionRef=React__namespace.useRef(null);const isRtl=wonderBlocksCore.useDirectionDetection(innerRef)==="rtl";React__namespace.useEffect(()=>{if(pendingSelectionRef.current&&innerRef.current){const[start,end]=pendingSelectionRef.current;innerRef.current.setSelectionRange(start,end);pendingSelectionRef.current=null;}},[value,innerRef]);return React__namespace.useCallback(e=>{const key=e.key;const isVerticalKey=key==="ArrowUp"||key==="ArrowDown";const isHorizontalKey=key==="ArrowLeft"||key==="ArrowRight";if(!isVerticalKey&&!isHorizontalKey){return false}if(!value){return false}const segments=getDateSegments(value,dateFormat,locale);if(!segments){return false}const offset=e.currentTarget.selectionStart??0;const segment=findSegmentAtOffset(segments,offset);if(!segment){return false}if(isHorizontalKey){const movesToNextSegment=isRtl?key==="ArrowLeft":key==="ArrowRight";const currentIndex=segments.indexOf(segment);const targetSegment=segments[currentIndex+(movesToNextSegment?1:-1)]??segment;e.preventDefault();innerRef.current?.setSelectionRange(targetSegment.start,targetSegment.end);return true}if(!parseDate){return false}const jsDate=parseDate(value,dateFormat,locale);if(!jsDate){return false}const currentDate=TemporalLocaleUtils.jsDateToTemporalDate(jsDate);const delta=key==="ArrowUp"?1:-1;const adjustedDate=adjustDateSegment(currentDate,segment.type,delta);const newValue=TemporalLocaleUtils.formatDate(adjustedDate,dateFormat,locale);const newSegments=getDateSegments(newValue,dateFormat,locale);const newSegment=newSegments?.find(s=>s.type===segment.type);pendingSelectionRef.current=newSegment?[newSegment.start,newSegment.end]:null;e.preventDefault();handleChange(newValue);return true},[value,dateFormat,locale,parseDate,handleChange,isRtl,innerRef])}
|
|
80
78
|
|
|
81
|
-
|
|
79
|
+
var modules_7c8e65e7={"root":"wb-date-picker-input-root-6e24f715","container":"wb-date-picker-input-container-6e24f715","icon":"wb-date-picker-input-icon-6e24f715","textField":"wb-date-picker-input-textField-6e24f715"};
|
|
80
|
+
|
|
81
|
+
const DatePickerInput=React__namespace.forwardRef((props,ref)=>{const{value:propValue,onBlur,onFocus,onKeyDown,onChange,dateFormat,locale=enUSLocaleCode,modifiers,getModifiersForDay,parseDate,placeholder,testId,resetInvalidValueOnBlur=true,["aria-label"]:ariaLabel,expanded,onToggleOverlay,onCalendarButtonKeyDown,calendarButtonAriaLabel,calendarButtonRef,...restProps}=props;const{strings}=wonderBlocksConfig.useWonderBlocksI18n();const[value,setValue]=React__namespace.useState(propValue);const lastPropValueRef=React__namespace.useRef(propValue);const keepInvalidTextRef=React__namespace.useRef(false);const lastTypedTextFormatValueRef=React__namespace.useRef(null);const processModifiers=React__namespace.useCallback((date,value)=>{if(!getModifiersForDay||!modifiers){return {}}return getModifiersForDay(date,modifiers).reduce((obj,modifier)=>({...obj,[modifier]:true}),{})},[getModifiersForDay,modifiers]);const updateDate=React__namespace.useCallback((date,inputValue)=>{if(onChange){onChange(date,processModifiers(date,inputValue),inputValue||undefined);}},[onChange,processModifiers]);const updateDateAsInvalid=React__namespace.useCallback(()=>{if(onChange){onChange(null,{});}},[onChange]);const processDate=React__namespace.useCallback(inputValue=>{if(!inputValue||inputValue.trim()===""){return}if(!parseDate){return}const date=parseDate(inputValue,dateFormat,locale);if(!date){return}return date},[parseDate,dateFormat,locale]);const isValid=React__namespace.useCallback(()=>{const date=processDate(value);if(!date){return false}const modifiersResult=processModifiers(date,value);if(modifiersResult.disabled){return false}return true},[value,processDate,processModifiers]);const isTextFormat=TemporalLocaleUtils.isTextFormatDate(dateFormat);React__namespace.useEffect(()=>{const propValueChanged=lastPropValueRef.current!==propValue;lastPropValueRef.current=propValue;if(propValueChanged){const safeProp=propValue??"";const safeValue=value??"";const isLastTypedValue=lastTypedTextFormatValueRef.current!==null&&value===lastTypedTextFormatValueRef.current;const bothHaveContent=safeValue!==""&&safeProp!=="";const oneIsPrefixOfOther=safeProp.startsWith(safeValue)||safeValue.startsWith(safeProp);const skipSyncUserTyping=isTextFormat&&propValue!==value&&(isLastTypedValue||bothHaveContent&&oneIsPrefixOfOther);if(keepInvalidTextRef.current&&(!propValue||propValue.trim()==="")){keepInvalidTextRef.current=false;}else if(skipSyncUserTyping){return}else if(propValue===value||(propValue??"")===(value??"")){keepInvalidTextRef.current=false;lastTypedTextFormatValueRef.current=null;return}else {setValue(propValue);keepInvalidTextRef.current=false;lastTypedTextFormatValueRef.current=null;}}},[propValue,isTextFormat,value]);wonderBlocksCore.useOnMountEffect(()=>{const skipValidation=dateFormat==="LL"&&propValue;if(!skipValidation&&!isValid()){updateDateAsInvalid();}});const handleFocus=e=>{if(onFocus){onFocus(e);}};const pendingValidationRef=React__namespace.useRef(false);const validateInput=React__namespace.useCallback(()=>{lastTypedTextFormatValueRef.current=null;const date=processDate(value);if(date){const modifiersResult=processModifiers(date,value);if(!modifiersResult.disabled){updateDate(date,value);}else {if(!resetInvalidValueOnBlur){keepInvalidTextRef.current=true;updateDate(date,value);}else {setValue(propValue);}}}else if(value&&value.trim()!==""){if(!resetInvalidValueOnBlur){keepInvalidTextRef.current=true;updateDateAsInvalid();}else {setValue(propValue);}}else {setValue(propValue);}},[value,processDate,processModifiers,resetInvalidValueOnBlur,propValue,updateDate,updateDateAsInvalid]);const handleBlur=e=>{const movingToCalendar=e.relatedTarget instanceof HTMLElement&&e.relatedTarget.closest('[data-testid="date-picker-overlay"]')!==null;if(movingToCalendar){pendingValidationRef.current=true;if(onBlur){onBlur(e);}return}validateInput();if(onBlur){onBlur(e);}};const innerRef=React__namespace.useRef(null);const handleChange=newValue=>{setValue(newValue);const date=processDate(newValue);if(date){const modifiersResult=processModifiers(date,newValue);if(isTextFormat){lastTypedTextFormatValueRef.current=newValue;}if(!modifiersResult.disabled){updateDate(date,newValue);}else if(!resetInvalidValueOnBlur){keepInvalidTextRef.current=true;updateDate(date,newValue);}else {updateDate(date,newValue);}}else if(!resetInvalidValueOnBlur&&newValue&&newValue.trim()!==""){keepInvalidTextRef.current=true;updateDateAsInvalid();}};const handleSegmentKeyDown=useDateSegmentArrowKeys({value,dateFormat,locale,parseDate,handleChange,innerRef});const handleInputKeyDown=e=>{if(!expanded&&handleSegmentKeyDown(e)){return}onKeyDown?.(e);};React__namespace.useImperativeHandle(ref,()=>{const inputElement=innerRef.current;if(!inputElement){return null}inputElement.validateInput=()=>{pendingValidationRef.current=false;validateInput();};return inputElement});return jsxRuntime.jsxs(wonderBlocksCore.View,{style:[modules_7c8e65e7.root,modules_7c8e65e7.container],children:[jsxRuntime.jsx(wonderBlocksForm.TextField,{ref:innerRef,...restProps,onBlur:handleBlur,onFocus:handleFocus,onKeyDown:handleInputKeyDown,onChange:handleChange,disabled:restProps.disabled,placeholder:placeholder,value:value??"",testId:testId,"aria-label":ariaLabel,autoComplete:"off",type:"text",style:modules_7c8e65e7.textField}),jsxRuntime.jsx(IconButton__default["default"],{ref:calendarButtonRef,icon:calendarIcon__default["default"],size:"small",kind:"tertiary",actionType:"neutral",disabled:restProps.disabled,"aria-label":calendarButtonAriaLabel||strings.iconAltToggleCalendar,"aria-expanded":expanded,"aria-haspopup":"grid",onClick:()=>onToggleOverlay(),onKeyDown:onCalendarButtonKeyDown,style:modules_7c8e65e7.icon})]})});var DatePickerInput$1 = DatePickerInput;
|
|
82
82
|
|
|
83
83
|
function FocusManager(props){const{children,referenceElement,onStartFocused,onEndFocused}=props;const rootNodeRef=React__namespace.useRef(null);const focusableElementsRef=React__namespace.useRef([]);const focusableElementsInsideRef=React__namespace.useRef([]);const nextFocusableElementRef=React__namespace.useRef(null);const getFocusableElements=React__namespace.useCallback(()=>{return wonderBlocksCore.findFocusableNodes(document)},[]);const getReferenceIndex=React__namespace.useCallback(()=>{if(!referenceElement){return -1}return focusableElementsRef.current.indexOf(referenceElement)},[referenceElement]);const getNextFocusableElement=React__namespace.useCallback(()=>{const referenceIndex=getReferenceIndex();if(referenceIndex>=0){const nextElementIndex=referenceIndex<focusableElementsRef.current.length-1?referenceIndex+1:0;return focusableElementsRef.current[nextElementIndex]}return undefined},[getReferenceIndex]);React__namespace.useEffect(()=>{focusableElementsRef.current=getFocusableElements();nextFocusableElementRef.current=getNextFocusableElement();const handleKeydownReferenceElement=e=>{if(e.key==="Tab"&&!e.shiftKey){if(rootNodeRef.current){focusableElementsInsideRef.current=wonderBlocksCore.findFocusableNodes(rootNodeRef.current);}if(focusableElementsInsideRef.current.length>0){e.preventDefault();focusableElementsInsideRef.current[0]?.focus();}}};const handleKeydownNextFocusableElement=e=>{if(e.key==="Tab"&&e.shiftKey){if(rootNodeRef.current){focusableElementsInsideRef.current=wonderBlocksCore.findFocusableNodes(rootNodeRef.current);}if(focusableElementsInsideRef.current.length>0){e.preventDefault();const lastIndex=focusableElementsInsideRef.current.length-1;focusableElementsInsideRef.current[lastIndex]?.focus();}}};if(referenceElement){referenceElement.addEventListener("keydown",handleKeydownReferenceElement,true);}if(nextFocusableElementRef.current){nextFocusableElementRef.current.addEventListener("keydown",handleKeydownNextFocusableElement,true);}return ()=>{if(referenceElement){referenceElement.removeEventListener("keydown",handleKeydownReferenceElement,true);}if(nextFocusableElementRef.current){nextFocusableElementRef.current.removeEventListener("keydown",handleKeydownNextFocusableElement,true);}}},[referenceElement,getNextFocusableElement,getFocusableElements]);const setComponentRootNode=React__namespace.useCallback(node=>{if(!node){return}rootNodeRef.current=node;focusableElementsInsideRef.current=wonderBlocksCore.findFocusableNodes(node);},[]);const handleFocusPreviousFocusableElement=React__namespace.useCallback(()=>{if(referenceElement){referenceElement.focus();}if(onStartFocused){onStartFocused();}},[referenceElement,onStartFocused]);const handleFocusNextFocusableElement=React__namespace.useCallback(()=>{if(nextFocusableElementRef.current){nextFocusableElementRef.current.focus();}if(onEndFocused){onEndFocused();}},[onEndFocused]);return jsxRuntime.jsxs(React__namespace.Fragment,{children:[jsxRuntime.jsx("div",{tabIndex:0,"data-testid":"focus-sentinel-prev",onFocus:handleFocusPreviousFocusableElement,style:{position:"fixed"}}),jsxRuntime.jsx("div",{"data-testid":"date-picker-overlay",ref:setComponentRootNode,children:children}),jsxRuntime.jsx("div",{tabIndex:0,"data-testid":"focus-sentinel-next",onFocus:handleFocusNextFocusableElement,style:{position:"fixed"}})]})}
|
|
84
84
|
|
|
85
|
-
const DEFAULT_STYLE={background:wonderBlocksTokens.semanticColor.core.background.base.default,borderRadius:wonderBlocksTokens.border.radius.radius_040,border:`solid ${wonderBlocksTokens.border.width.thin} ${wonderBlocksTokens.semanticColor.core.border.neutral.subtle}`,boxShadow:wonderBlocksTokens.boxShadow.mid};const BASE_CONTAINER_STYLES={fontFamily:wonderBlocksTokens.font.family.sans,padding:wonderBlocksTokens.sizing.size_100};const OUT_OF_BOUNDARIES_STYLES={visibility:"hidden"};const DatePickerOverlay=({children,referenceElement,focusReferenceElement,onClose,dir="ltr",style=DEFAULT_STYLE,calendarGridRegionAriaLabel})=>{const{strings}=wonderBlocksConfig.useWonderBlocksI18n();if(!referenceElement){return null}const placement=dir==="rtl"?"bottom-end":"bottom-start";const modalHost=wonderBlocksModal.maybeGetPortalMountedModalHostElement(referenceElement)||document.querySelector("body");if(!modalHost){return null}return reactDom.createPortal(jsxRuntime.jsx(FocusManager,{referenceElement:focusReferenceElement??referenceElement,onEndFocused:onClose,children:jsxRuntime.jsx(reactPopper.Popper,{referenceElement:referenceElement,placement:placement,strategy:"fixed",modifiers:[{name:"preventOverflow",options:{rootBoundary:"viewport"}}],children:({placement,ref,style:popperStyle,isReferenceHidden,hasPopperEscaped})=>{const isTestEnvironment=typeof window!=="undefined"&&window.navigator.userAgent.includes("jsdom");const outOfBoundaries=!isTestEnvironment&&(isReferenceHidden||hasPopperEscaped);const combinedStyles={...BASE_CONTAINER_STYLES,...popperStyle,...
|
|
85
|
+
const DEFAULT_STYLE={background:wonderBlocksTokens.semanticColor.core.background.base.default,borderRadius:wonderBlocksTokens.border.radius.radius_040,border:`solid ${wonderBlocksTokens.border.width.thin} ${wonderBlocksTokens.semanticColor.core.border.neutral.subtle}`,boxShadow:wonderBlocksTokens.boxShadow.mid};const BASE_CONTAINER_STYLES={fontFamily:wonderBlocksTokens.font.family.sans,padding:wonderBlocksTokens.sizing.size_100};const OUT_OF_BOUNDARIES_STYLES={visibility:"hidden"};const DatePickerOverlay=({children,referenceElement,focusReferenceElement,onClose,dir="ltr",style=DEFAULT_STYLE,calendarGridRegionAriaLabel})=>{const{strings}=wonderBlocksConfig.useWonderBlocksI18n();if(!referenceElement){return null}const placement=dir==="rtl"?"bottom-end":"bottom-start";const modalHost=wonderBlocksModal.maybeGetPortalMountedModalHostElement(referenceElement)||document.querySelector("body");if(!modalHost){return null}return reactDom.createPortal(jsxRuntime.jsx(FocusManager,{referenceElement:focusReferenceElement??referenceElement,onEndFocused:onClose,children:jsxRuntime.jsx(reactPopper.Popper,{referenceElement:referenceElement,placement:placement,strategy:"fixed",modifiers:[{name:"preventOverflow",options:{rootBoundary:"viewport"}}],children:({placement,ref,style:popperStyle,isReferenceHidden,hasPopperEscaped})=>{const isTestEnvironment=typeof window!=="undefined"&&window.navigator.userAgent.includes("jsdom");const outOfBoundaries=!isTestEnvironment&&(isReferenceHidden||hasPopperEscaped);const customStyle=style&&typeof style==="object"&&!Array.isArray(style)?style:null;const combinedStyles={...BASE_CONTAINER_STYLES,...popperStyle,...customStyle,...outOfBoundaries&&OUT_OF_BOUNDARIES_STYLES};return jsxRuntime.jsx("div",{"aria-label":calendarGridRegionAriaLabel||strings.datePickerCalendar,ref:ref,role:"region",style:combinedStyles,"data-placement":placement,children:children})}})}),modalHost)};var DatePickerOverlay$1 = DatePickerOverlay;
|
|
86
|
+
|
|
87
|
+
var modules_ded9cff2={"overlayRoot":"wb-date-picker-overlayRoot-325d8b69","footer":"wb-date-picker-footer-325d8b69","dayButton":"wb-date-picker-dayButton-325d8b69"};
|
|
86
88
|
|
|
87
|
-
const customRootStyle={"--rdp-accent-color":wonderBlocksTokens.semanticColor.core.border.instructive.default,"--rdp-today-color":wonderBlocksTokens.semanticColor.core.foreground.instructive.default};const
|
|
89
|
+
const customRootStyle={"--rdp-accent-color":wonderBlocksTokens.semanticColor.core.border.instructive.default,"--rdp-today-color":wonderBlocksTokens.semanticColor.core.foreground.instructive.default};const dayPickerClassNames={[reactDayPicker.UI.DayButton]:`${reactDayPicker.getDefaultClassNames()[reactDayPicker.UI.DayButton]} ${modules_ded9cff2.dayButton}`};const DatePicker=props=>{const{locale: locale$1,updateDate,dateFormat,disabled,id,maxDate,minDate,inputAriaLabel,calendarButtonAriaLabel,calendarGridRegionAriaLabel,placeholder,selectedDate,style,closeOnSelect=true,resetInvalidValueOnBlur=true,footer}=props;const[showOverlay,setShowOverlay]=React__namespace.useState(false);const[currentDate,setCurrentDate]=React__namespace.useState(selectedDate);const datePickerInputRef=React__namespace.useRef(null);const calendarButtonRef=React__namespace.useRef(null);const datePickerRef=React__namespace.useRef(null);const refWrapper=React__namespace.useRef(null);const skipNextOpenRef=React__namespace.useRef(false);const movingFocusIntoOverlayRef=React__namespace.useRef(false);const{handleEscapeKeyDown}=useEscapeKeyupCapture();const{displayMonth,setDisplayMonth,displayMonthRef,inputDrivenMonthRef,setDisplayMonthAndRefs}=useDisplayMonth({selectedDate});const open=React__namespace.useCallback(()=>{if(skipNextOpenRef.current){skipNextOpenRef.current=false;return}if(!disabled){if(selectedDate!=null){const jsDate=TemporalLocaleUtils.temporalDateToJsDate(selectedDate);setDisplayMonthAndRefs(jsDate);}else {displayMonthRef.current=displayMonthRef.current??displayMonth;}setShowOverlay(true);}},[disabled,displayMonth,displayMonthRef,selectedDate,setDisplayMonthAndRefs,skipNextOpenRef]);const{handleInputChange,clearInputDrivenMonth}=useOverlayMonthFromInput({inputDrivenMonthRef,setDisplayMonth,setDisplayMonthAndRefs,setCurrentDate,updateDate,dateFormat,localeCode:locale$1?.code});const close=React__namespace.useCallback(()=>{clearInputDrivenMonth();if(selectedDate!=null){const jsDate=TemporalLocaleUtils.temporalDateToJsDate(selectedDate);setDisplayMonthAndRefs(jsDate);}else {setDisplayMonthAndRefs(null);}setShowOverlay(false);datePickerInputRef.current?.validateInput?.();},[selectedDate,setDisplayMonthAndRefs,clearInputDrivenMonth,datePickerInputRef]);const handleToggleOverlay=React__namespace.useCallback(()=>{if(disabled){return}if(showOverlay){close();}else {skipNextOpenRef.current=false;open();}},[disabled,showOverlay,close,open,skipNextOpenRef]);const focusIntoOverlay=React__namespace.useCallback(()=>{const overlayRoot=datePickerRef.current;if(!overlayRoot){return}const grid=overlayRoot.querySelector('[role="grid"]');const rovingTarget=grid?.querySelector('[tabindex="0"]');const target=rovingTarget??wonderBlocksCore.findFocusableNodes(grid??overlayRoot)[0];if(target){movingFocusIntoOverlayRef.current=true;target.focus();}},[datePickerRef]);useCloseOnOutsideClick({refWrapper,datePickerRef,showOverlay,closeOnSelect,close});useSelectedDateSync({selectedDate,setCurrentDate,setDisplayMonthAndRefs});const computedLocale=locale$1??locale.enUS;const selectedDateValue=currentDate?TemporalLocaleUtils.temporalDateToJsDate(currentDate):undefined;const modifiers=useDatePickerModifiers({selectedDateValue,minDate,maxDate});const formatDateForInput=useFormatDateForInput({dateFormat,locale:computedLocale});const dir=refWrapper.current?.closest("[dir]")?.getAttribute("dir")||"ltr";const handleMonthChange=React__namespace.useCallback(newMonth=>{clearInputDrivenMonth();setDisplayMonthAndRefs(newMonth);},[clearInputDrivenMonth,setDisplayMonthAndRefs]);const isLeavingDropdown=e=>{const dayPickerCalendar=datePickerRef.current;if(!(e.relatedTarget instanceof Node)){return true}if(dayPickerCalendar?.contains(e.relatedTarget)){return false}const calendarButton=calendarButtonRef.current;if(calendarButton?.contains(e.relatedTarget)){return false}return true};const handleInputBlur=e=>{if(movingFocusIntoOverlayRef.current){movingFocusIntoOverlayRef.current=false;return}if(isLeavingDropdown(e)){close();}};const onEscapeCloseOverlay=React__namespace.useCallback(()=>{skipNextOpenRef.current=true;close();calendarButtonRef.current?.focus();},[close,skipNextOpenRef]);const handleKeyDown=e=>{if(!showOverlay){return}if(e.key==="Escape"){handleEscapeKeyDown(e,onEscapeCloseOverlay);}if(e.key==="ArrowDown"){e.preventDefault();focusIntoOverlay();}if(e.key==="Enter"){e.preventDefault();if(closeOnSelect){close();}}};const handleCalendarButtonKeyDown=React__namespace.useCallback(e=>{if(e.key==="ArrowDown"&&showOverlay){e.preventDefault();focusIntoOverlay();}else if(e.key==="Escape"&&showOverlay){handleEscapeKeyDown(e,onEscapeCloseOverlay);}},[showOverlay,focusIntoOverlay,handleEscapeKeyDown,onEscapeCloseOverlay]);const RootWithEsc=React__namespace.useCallback(props=>{const{onKeyDown,rootRef:_,...rest}=props;return jsxRuntime.jsx("div",{...rest,tabIndex:-1,onKeyDown:e=>{onKeyDown?.(e);if(e.key==="Escape"){handleEscapeKeyDown(e,onEscapeCloseOverlay);}}})},[handleEscapeKeyDown,onEscapeCloseOverlay]);const dayPickerComponents=React__namespace.useMemo(()=>({Root:RootWithEsc}),[RootWithEsc]);const handleDayClick=React__namespace.useCallback((date,{disabled})=>{if(disabled||!date){return}datePickerInputRef.current?.focus();const wrappedDate=TemporalLocaleUtils.jsDateToTemporalDate(date);setCurrentDate(wrappedDate);const monthDate=new Date(date);clearInputDrivenMonth();setDisplayMonthAndRefs(monthDate);updateDate(wrappedDate);setShowOverlay(!closeOnSelect);},[updateDate,closeOnSelect,setDisplayMonthAndRefs,datePickerInputRef,clearInputDrivenMonth]);const renderInput=inputModifiers=>{const selectedDateAsValue=formatDateForInput(currentDate);return jsxRuntime.jsx(DatePickerInput$1,{onBlur:handleInputBlur,onChange:handleInputChange,onKeyDown:handleKeyDown,"aria-label":inputAriaLabel,disabled:disabled,id:id,placeholder:placeholder,value:selectedDateAsValue,ref:datePickerInputRef,dateFormat:dateFormat,locale:computedLocale.code,parseDate:TemporalLocaleUtils.parseDateToJsDate,getModifiersForDay:TemporalLocaleUtils.getModifiersForDay,modifiers:inputModifiers,resetInvalidValueOnBlur:resetInvalidValueOnBlur,testId:id&&`${id}-input`,expanded:showOverlay,onToggleOverlay:handleToggleOverlay,onCalendarButtonKeyDown:handleCalendarButtonKeyDown,calendarButtonAriaLabel:calendarButtonAriaLabel,calendarButtonRef:calendarButtonRef})};const maybeRenderFooter=()=>{if(!footer){return null}return jsxRuntime.jsx(wonderBlocksCore.View,{testId:"date-picker-footer",style:modules_ded9cff2.footer,children:footer({close})})};const minDateToShow=minDate&&selectedDateValue?temporalPolyfill.Temporal.PlainDate.compare(minDate,currentDate)<0?TemporalLocaleUtils.temporalDateToJsDate(minDate):selectedDateValue:minDate?TemporalLocaleUtils.temporalDateToJsDate(minDate):undefined;const dayPickerEndMonth=React__namespace.useMemo(()=>maxDate?TemporalLocaleUtils.temporalDateToJsDate(maxDate):undefined,[maxDate]);const dayPickerStyles=React__namespace.useMemo(()=>({root:{...customRootStyle},nav:{width:"auto"}}),[]);const dayPickerModifiersStyles=React__namespace.useMemo(()=>({selected:{fontWeight:wonderBlocksTokens.font.weight.medium},today:{fontWeight:wonderBlocksTokens.font.weight.bold}}),[]);const inputDrivenMonth=inputDrivenMonthRef.current;const isInputDriven=inputDrivenMonth!=null;const selectedDateAsJs=selectedDate!=null?TemporalLocaleUtils.temporalDateToJsDate(selectedDate):undefined;const baseMonth=displayMonthRef.current??(showOverlay&&selectedDateAsJs?selectedDateAsJs:undefined)??displayMonth??selectedDateValue??new Date;const firstOfBaseMonth=new Date(baseMonth.getFullYear(),baseMonth.getMonth(),1);const pickerKey=isInputDriven?`input-${inputDrivenMonth.getTime()}`:`picker-${baseMonth.getTime()}`;const inputDrivenMonthMs=inputDrivenMonth?.getTime();const firstOfBaseMonthMs=firstOfBaseMonth.getTime();const dayPickerMonthProps=React__namespace.useMemo(()=>{if(isInputDriven&&inputDrivenMonthMs!=null){const d=new Date(inputDrivenMonthMs);return {month:new Date(d.getFullYear(),d.getMonth(),1),onMonthChange:handleMonthChange}}return {defaultMonth:new Date(firstOfBaseMonthMs)}},[isInputDriven,inputDrivenMonthMs,firstOfBaseMonthMs,handleMonthChange]);return jsxRuntime.jsxs(wonderBlocksCore.View,{style:style,ref:refWrapper,children:[renderInput(modifiers),showOverlay&&jsxRuntime.jsx(DatePickerOverlay$1,{referenceElement:datePickerInputRef.current,focusReferenceElement:calendarButtonRef.current??undefined,onClose:close,dir:dir==="rtl"?"rtl":"ltr",calendarGridRegionAriaLabel:calendarGridRegionAriaLabel,children:jsxRuntime.jsxs(wonderBlocksCore.View,{ref:datePickerRef,style:modules_ded9cff2.overlayRoot,children:[jsxRuntime.jsx(reactDayPicker.DayPicker,{mode:"single",selected:selectedDateValue,...dayPickerMonthProps,startMonth:minDateToShow??undefined,endMonth:dayPickerEndMonth,modifiers:modifiers,onDayClick:handleDayClick,components:dayPickerComponents,locale:computedLocale,dir:dir,styles:dayPickerStyles,modifiersStyles:dayPickerModifiersStyles,classNames:dayPickerClassNames},pickerKey),maybeRenderFooter()]})})]})};DatePicker.defaultProps={closeOnSelect:true};var DatePicker$1 = DatePicker;
|
|
88
90
|
|
|
89
|
-
exports.DatePicker = DatePicker;
|
|
91
|
+
exports.DatePicker = DatePicker$1;
|
|
90
92
|
exports.TemporalLocaleUtils = TemporalLocaleUtils;
|
|
93
|
+
|
|
94
|
+
require("./index.css");
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Date picker component for Wonder Blocks.",
|
|
4
4
|
"author": "Khan Academy",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "
|
|
6
|
+
"version": "2.0.0",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -19,27 +19,34 @@
|
|
|
19
19
|
"main": "dist/index.js",
|
|
20
20
|
"module": "dist/es/index.js",
|
|
21
21
|
"types": "dist/index.d.ts",
|
|
22
|
+
"sideEffects": [
|
|
23
|
+
"**/*.css"
|
|
24
|
+
],
|
|
22
25
|
"exports": {
|
|
23
26
|
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
24
28
|
"import": "./dist/es/index.js",
|
|
25
|
-
"require": "./dist/index.js"
|
|
26
|
-
|
|
29
|
+
"require": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./css": {
|
|
32
|
+
"import": "./dist/es/index.css",
|
|
33
|
+
"require": "./dist/index.css",
|
|
34
|
+
"default": "./dist/index.css"
|
|
27
35
|
}
|
|
28
36
|
},
|
|
29
37
|
"dependencies": {
|
|
30
38
|
"react-day-picker": "^9.11.1",
|
|
31
39
|
"@khanacademy/wonder-blocks-config": "0.7.1",
|
|
32
|
-
"@khanacademy/wonder-blocks-core": "
|
|
33
|
-
"@khanacademy/wonder-blocks-form": "
|
|
34
|
-
"@khanacademy/wonder-blocks-icon-button": "
|
|
35
|
-
"@khanacademy/wonder-blocks-modal": "
|
|
36
|
-
"@khanacademy/wonder-blocks-styles": "0.
|
|
37
|
-
"@khanacademy/wonder-blocks-tokens": "18.
|
|
40
|
+
"@khanacademy/wonder-blocks-core": "13.0.0",
|
|
41
|
+
"@khanacademy/wonder-blocks-form": "8.0.0",
|
|
42
|
+
"@khanacademy/wonder-blocks-icon-button": "13.0.0",
|
|
43
|
+
"@khanacademy/wonder-blocks-modal": "9.0.0",
|
|
44
|
+
"@khanacademy/wonder-blocks-styles": "1.0.0",
|
|
45
|
+
"@khanacademy/wonder-blocks-tokens": "18.3.0"
|
|
38
46
|
},
|
|
39
47
|
"peerDependencies": {
|
|
40
48
|
"@phosphor-icons/core": "^2.0.2",
|
|
41
49
|
"@popperjs/core": "^2.10.1",
|
|
42
|
-
"aphrodite": "^1.2.5",
|
|
43
50
|
"date-fns": "^4.1.0",
|
|
44
51
|
"react": "18.2.0",
|
|
45
52
|
"react-dom": "18.2.0",
|