@khanacademy/wonder-blocks-birthday-picker 4.2.10 → 5.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 +84 -0
- package/dist/es/index.css +71 -0
- package/dist/es/index.css.map +1 -0
- package/dist/es/index.js +7 -4
- package/dist/index.css +71 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +6 -3
- package/package.json +22 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,89 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-birthday-picker
|
|
2
2
|
|
|
3
|
+
## 5.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- f52e4cd: Add an `exports` map (`.` and `./css`) and `"sideEffects": ["**/*.css"]` to the package.json. `./css` is the component stylesheet. It's conditional: `import` resolves to `dist/es/index.css` and `require` to `dist/index.css`, the same copy each JS entry already loads, so importing `./css` too doesn't duplicate the CSS.
|
|
8
|
+
|
|
9
|
+
**Breaking:** the new `exports` map blocks deep imports such as `@khanacademy/wonder-blocks-core/dist/...`. Import from the package root instead. No deep imports of these packages were found in Khan/frontend or Khan/perseus.
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- cd0be20: Migrate `BirthdayPicker` from Aphrodite to CSS Modules (WB-2335, CSS Modules
|
|
14
|
+
Phase 5 / Wave G). The public component API is unchanged: same props, DOM
|
|
15
|
+
structure, and `style` / `dropdownStyle` overrides.
|
|
16
|
+
|
|
17
|
+
- Styling now lives in `birthday-picker.module.css`, including the styles
|
|
18
|
+
passed into each `SingleSelect`. The selects' minimum widths (110px, 167px
|
|
19
|
+
with `monthYearOnly`, 100px for the day) are now classes instead of inline
|
|
20
|
+
style objects.
|
|
21
|
+
- Rules are nested under a marker class on the row and on the error row, so
|
|
22
|
+
they beat `View`, `SingleSelect`'s wrapper and `BodyText` on specificity
|
|
23
|
+
rather than stylesheet load order.
|
|
24
|
+
- The small-screen (`xsOrSmaller`, ≤567px) stacked, full-width layout uses `!important`
|
|
25
|
+
inside its `@media` block. That's the only way a layered rule can outrank
|
|
26
|
+
the consumer's Aphrodite overrides, and it keeps the old behavior: on small
|
|
27
|
+
screens the stacked layout wins over `style` / `dropdownStyle`, and on
|
|
28
|
+
larger screens the consumer's overrides win.
|
|
29
|
+
- **Behavior change (edge case):** a `minWidth` passed in `dropdownStyle` as
|
|
30
|
+
an Aphrodite `StyleSheet` now applies on larger screens. Before, the
|
|
31
|
+
component's own minimum width silently won over it, though a plain-object
|
|
32
|
+
`dropdownStyle` already won.
|
|
33
|
+
- The package now ships `dist/index.css` (auto side-effect import) and marks
|
|
34
|
+
`**/*.css` as `sideEffects`. `aphrodite` is dropped from `peerDependencies`
|
|
35
|
+
(the package no longer imports it).
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- 0b6c478: Add breakpoint custom media queries for CSS. `@khanacademy/wonder-blocks-tokens/custom-media.css`
|
|
40
|
+
defines one `@custom-media` per `breakpoint.mediaQuery` token (e.g.
|
|
41
|
+
`@media (--wb-breakpoint-mediaQuery-mdOrLarger)`). Expand them at build time by
|
|
42
|
+
adding `@csstools/postcss-global-data` (with
|
|
43
|
+
`files: [require.resolve("@khanacademy/wonder-blocks-tokens/custom-media.css")]`)
|
|
44
|
+
and `postcss-custom-media` to your PostCSS config. `NavigationTabItem` now uses the `mdOrLarger` breakpoint;
|
|
45
|
+
its emitted query changes from `(width >= 682px)` to the equivalent
|
|
46
|
+
`(min-width: 682px)`, matching the Aphrodite token and supporting Safari < 16.4.
|
|
47
|
+
|
|
48
|
+
`BirthdayPicker` now stacks its selects at the `xsOrSmaller` breakpoint
|
|
49
|
+
(`max-width: 567px`, previously a hard-coded `max-width: 520px`).
|
|
50
|
+
|
|
51
|
+
- 9652f57: Load each package's CSS after the CSS of the Wonder Blocks packages it depends
|
|
52
|
+
on. The published JS imported its own `index.css` before its dependencies, so
|
|
53
|
+
bundlers emitted, for example, Button's CSS before Typography's. Both sit in
|
|
54
|
+
`@layer shared` with single-class selectors, so the later `BodyText` rule won and
|
|
55
|
+
Button labels lost their own `font-weight`, `line-height` and `font-size`. The CSS
|
|
56
|
+
import now comes after the dependency imports, matching the source order that
|
|
57
|
+
Storybook already uses.
|
|
58
|
+
- Updated dependencies [0c6d97d]
|
|
59
|
+
- Updated dependencies [185dbbc]
|
|
60
|
+
- Updated dependencies [0b6c478]
|
|
61
|
+
- Updated dependencies [9652f57]
|
|
62
|
+
- Updated dependencies [aa5a8e1]
|
|
63
|
+
- Updated dependencies [f52e4cd]
|
|
64
|
+
- Updated dependencies [f52e4cd]
|
|
65
|
+
- Updated dependencies [647e025]
|
|
66
|
+
- Updated dependencies [b66b7b7]
|
|
67
|
+
- Updated dependencies [dbb8f0f]
|
|
68
|
+
- Updated dependencies [be9c311]
|
|
69
|
+
- Updated dependencies [b8a32c8]
|
|
70
|
+
- Updated dependencies [14e0d32]
|
|
71
|
+
- Updated dependencies [d5316c4]
|
|
72
|
+
- Updated dependencies [bcc10a1]
|
|
73
|
+
- Updated dependencies [ea22448]
|
|
74
|
+
- Updated dependencies [82ae405]
|
|
75
|
+
- Updated dependencies [ad52f4b]
|
|
76
|
+
- Updated dependencies [9c09ca7]
|
|
77
|
+
- Updated dependencies [a1002be]
|
|
78
|
+
- Updated dependencies [b9156f8]
|
|
79
|
+
- Updated dependencies [44dac93]
|
|
80
|
+
- @khanacademy/wonder-blocks-tokens@18.3.0
|
|
81
|
+
- @khanacademy/wonder-blocks-core@13.0.0
|
|
82
|
+
- @khanacademy/wonder-blocks-dropdown@12.0.0
|
|
83
|
+
- @khanacademy/wonder-blocks-icon@7.0.0
|
|
84
|
+
- @khanacademy/wonder-blocks-layout@5.0.0
|
|
85
|
+
- @khanacademy/wonder-blocks-typography@6.0.0
|
|
86
|
+
|
|
3
87
|
## 4.2.10
|
|
4
88
|
|
|
5
89
|
### Patch Changes
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
@layer shared {/**
|
|
2
|
+
* BirthdayPicker styles
|
|
3
|
+
*
|
|
4
|
+
* Every rule is nested inside `.root`, a marker class that carries no
|
|
5
|
+
* declarations of its own. It sits on both top-level elements (the row of
|
|
6
|
+
* selects and the error row), which are `View`s. The selects' `style` lands
|
|
7
|
+
* on `SingleSelect`'s wrapper `View` (`DropdownCore`'s `menuWrapper`), and the
|
|
8
|
+
* error text is a `BodyText`. All of those ship rules in the same
|
|
9
|
+
* `@layer shared` that set properties overridden below (`flex-direction`,
|
|
10
|
+
* `min-inline-size`, `margin`, …). The bundle loads this package's CSS before
|
|
11
|
+
* its dependencies', so the compound selectors make these rules win on
|
|
12
|
+
* specificity rather than load order.
|
|
13
|
+
*
|
|
14
|
+
* The small-screen `@media` block comes last and its declarations are
|
|
15
|
+
* `!important`. On small screens the full-width, stacked layout must win over
|
|
16
|
+
* the consumer's `style` / `dropdownStyle` (and over the selects' minimum
|
|
17
|
+
* widths), while on larger screens the consumer's overrides win. The
|
|
18
|
+
* consumer's overrides are unlayered and `!important`, and only an
|
|
19
|
+
* `!important` declaration inside a cascade layer outranks those.
|
|
20
|
+
*
|
|
21
|
+
* Outside that block, the consumer's `style` and `dropdownStyle` (unlayered
|
|
22
|
+
* and `!important`) win over this module. The build wraps
|
|
23
|
+
* every rule in `@layer shared { … }`.
|
|
24
|
+
*/.wb-birthday-picker-root-6784a980 {
|
|
25
|
+
&.wb-birthday-picker-wrapper-6784a980 {
|
|
26
|
+
flex-direction: row;
|
|
27
|
+
gap: var(--wb-sizing-size_080);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* Minimum widths of the selects. */
|
|
31
|
+
|
|
32
|
+
/* Month and year when the full date of birth is shown. */
|
|
33
|
+
& .wb-birthday-picker-fieldFull-6784a980 {
|
|
34
|
+
min-inline-size: 110px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* Month and year when the day field is hidden (`monthYearOnly`).
|
|
38
|
+
* See: https://www.figma.com/file/uJZi9ZvuEz5N8GJ3HqKFAa/(2021)-Account-records?node-id=20%3A398 */
|
|
39
|
+
& .wb-birthday-picker-fieldMonthYear-6784a980 {
|
|
40
|
+
min-inline-size: 167px;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
& .wb-birthday-picker-fieldDay-6784a980 {
|
|
44
|
+
min-inline-size: 100px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&.wb-birthday-picker-errorRow-6784a980 {
|
|
48
|
+
flex-direction: row;
|
|
49
|
+
place-items: center;
|
|
50
|
+
gap: var(--wb-sizing-size_040);
|
|
51
|
+
margin-block-start: var(--wb-sizing-size_040);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
& .wb-birthday-picker-errorText-6784a980 {
|
|
55
|
+
color: var(--wb-semanticColor-core-foreground-critical-default);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* breakpoint.mediaQuery.xsOrSmaller (max-width: breakpoint.width.xsMax) */
|
|
59
|
+
@media screen and (max-width: 567px) {
|
|
60
|
+
&.wb-birthday-picker-wrapper-6784a980 {
|
|
61
|
+
flex-direction: column !important;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
& .wb-birthday-picker-input-6784a980 {
|
|
65
|
+
min-inline-size: 100% !important;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/*# sourceMappingURL=index.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["<no source>","../../src/components/birthday-picker.module.css"],"names":[],"mappings":"AAAA,eCAA;;;;;;;;;;;;;;;;;;;;;;;EAuBE,CAEF;IACI;QACI,mBAAmB;QACnB,8BAA8B;IAClC;;IAEA,mCAAmC;;IAEnC,yDAAyD;IACzD;QACI,sBAAsB;IAC1B;;IAEA;uGACmG;IACnG;QACI,sBAAsB;IAC1B;;IAEA;QACI,sBAAsB;IAC1B;;IAEA;QACI,mBAAmB;QACnB,mBAAmB;QACnB,8BAA8B;QAC9B,6CAA6C;IACjD;;IAEA;QACI,+DAA+D;IACnE;;IAEA,0EAA0E;IAC1E;QACI;YACI,iCAAiC;QACrC;;QAEA;YACI,gCAAgC;QACpC;IACJ;AACJ;CDrEA","file":"index.css","sourcesContent":[null,"/**\n * BirthdayPicker styles\n *\n * Every rule is nested inside `.root`, a marker class that carries no\n * declarations of its own. It sits on both top-level elements (the row of\n * selects and the error row), which are `View`s. The selects' `style` lands\n * on `SingleSelect`'s wrapper `View` (`DropdownCore`'s `menuWrapper`), and the\n * error text is a `BodyText`. All of those ship rules in the same\n * `@layer shared` that set properties overridden below (`flex-direction`,\n * `min-inline-size`, `margin`, …). The bundle loads this package's CSS before\n * its dependencies', so the compound selectors make these rules win on\n * specificity rather than load order.\n *\n * The small-screen `@media` block comes last and its declarations are\n * `!important`. On small screens the full-width, stacked layout must win over\n * the consumer's `style` / `dropdownStyle` (and over the selects' minimum\n * widths), while on larger screens the consumer's overrides win. The\n * consumer's overrides are unlayered and `!important`, and only an\n * `!important` declaration inside a cascade layer outranks those.\n *\n * Outside that block, the consumer's `style` and `dropdownStyle` (unlayered\n * and `!important`) win over this module. The build wraps\n * every rule in `@layer shared { … }`.\n */\n\n.root {\n &.wrapper {\n flex-direction: row;\n gap: var(--wb-sizing-size_080);\n }\n\n /* Minimum widths of the selects. */\n\n /* Month and year when the full date of birth is shown. */\n & .fieldFull {\n min-inline-size: 110px;\n }\n\n /* Month and year when the day field is hidden (`monthYearOnly`).\n * See: https://www.figma.com/file/uJZi9ZvuEz5N8GJ3HqKFAa/(2021)-Account-records?node-id=20%3A398 */\n & .fieldMonthYear {\n min-inline-size: 167px;\n }\n\n & .fieldDay {\n min-inline-size: 100px;\n }\n\n &.errorRow {\n flex-direction: row;\n place-items: center;\n gap: var(--wb-sizing-size_040);\n margin-block-start: var(--wb-sizing-size_040);\n }\n\n & .errorText {\n color: var(--wb-semanticColor-core-foreground-critical-default);\n }\n\n /* breakpoint.mediaQuery.xsOrSmaller (max-width: breakpoint.width.xsMax) */\n @media (--wb-breakpoint-mediaQuery-xsOrSmaller) {\n &.wrapper {\n flex-direction: column !important;\n }\n\n & .input {\n min-inline-size: 100% !important;\n }\n }\n}\n"]}
|
package/dist/es/index.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { Temporal } from 'temporal-polyfill';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import { StyleSheet } from 'aphrodite';
|
|
5
4
|
import { useWonderBlocksI18n } from '@khanacademy/wonder-blocks-config';
|
|
6
5
|
import { View } from '@khanacademy/wonder-blocks-core';
|
|
7
|
-
import {
|
|
6
|
+
import { semanticColor } from '@khanacademy/wonder-blocks-tokens';
|
|
8
7
|
import { BodyText } from '@khanacademy/wonder-blocks-typography';
|
|
9
8
|
import { PhosphorIcon } from '@khanacademy/wonder-blocks-icon';
|
|
10
9
|
import { SingleSelect, OptionItem } from '@khanacademy/wonder-blocks-dropdown';
|
|
11
10
|
import infoIcon from '@phosphor-icons/core/bold/info-bold.svg';
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
var modules_24b959f9={"root":"wb-birthday-picker-root-6784a980","wrapper":"wb-birthday-picker-wrapper-6784a980","fieldFull":"wb-birthday-picker-fieldFull-6784a980","fieldMonthYear":"wb-birthday-picker-fieldMonthYear-6784a980","fieldDay":"wb-birthday-picker-fieldDay-6784a980","errorRow":"wb-birthday-picker-errorRow-6784a980","errorText":"wb-birthday-picker-errorText-6784a980","input":"wb-birthday-picker-input-6784a980"};
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
const CUR_YEAR=new Date().getYear()+1900;const isFutureDate=date=>{return Temporal.PlainDate.compare(date,Temporal.Now.plainDateISO())===1};const getStateFromDefault=(defaultValue,monthYearOnly,labels)=>{const initialState={month:null,day:monthYearOnly?"1":null,year:null,error:null};if(defaultValue){let date=null;try{date=Temporal.PlainDate.from(defaultValue);}catch(err){initialState.error=labels.errorMessage;return initialState}if(monthYearOnly){date=date.with({day:date.daysInMonth});}initialState.month=String(date.month);initialState.day=String(date.day);initialState.year=String(date.year);if(isFutureDate(date)){initialState.error=labels.errorMessage;}}return initialState};const getMonthYearStyle=monthYearOnly=>monthYearOnly?modules_24b959f9.fieldMonthYear:modules_24b959f9.fieldFull;const BirthdayPicker=props=>{const{defaultValue,disabled,dropdownStyle,locale,monthYearOnly,onChange,style}=props;const{strings}=useWonderBlocksI18n();const labelsRef=React.useRef({errorMessage:props.labels?.errorMessage||strings.birthdateErrorMessage,month:props.labels?.month||strings.fieldLabelMonth,year:props.labels?.year||strings.fieldLabelYear,day:props.labels?.day||strings.fieldLabelDay});const labels=labelsRef.current;const[initialState]=React.useState(()=>getStateFromDefault(defaultValue,monthYearOnly,labels));const[month,setMonth]=React.useState(initialState.month);const[day,setDay]=React.useState(initialState.day);const[year,setYear]=React.useState(initialState.year);const[error,setError]=React.useState(initialState.error);const valuesRef=React.useRef({month:initialState.month,day:initialState.day,year:initialState.year});const lastChangeValueRef=React.useRef(defaultValue||null);const reportChange=React.useCallback(value=>{if(value!==lastChangeValueRef.current){lastChangeValueRef.current=value;onChange(value);}},[onChange]);const handleChange=React.useCallback(()=>{const{month,day,year}=valuesRef.current;const dateFields=[year,month];if(!monthYearOnly){dateFields.push(day);}if(dateFields.some(field=>field===null)){reportChange(null);return}let date;try{if(monthYearOnly){date=Temporal.PlainDate.from({year:Number(year),month:Number(month),day:31});}else {date=Temporal.PlainDate.from({year:Number(year),month:Number(month),day:Number(day)},{overflow:"reject"});}}catch(err){setError(labels.errorMessage);reportChange(null);return}if(isFutureDate(date)){setError(labels.errorMessage);reportChange(null);}else {setError(null);reportChange(date.toString());}},[labels,monthYearOnly,reportChange]);const handleMonthChange=React.useCallback(month=>{valuesRef.current={...valuesRef.current,month};setMonth(month);handleChange();},[handleChange]);const handleDayChange=React.useCallback(day=>{valuesRef.current={...valuesRef.current,day};setDay(day);handleChange();},[handleChange]);const handleYearChange=React.useCallback(year=>{valuesRef.current={...valuesRef.current,year};setYear(year);handleChange();},[handleChange]);const maybeRenderError=()=>{if(!error){return null}return jsxs(View,{style:[modules_24b959f9.root,modules_24b959f9.errorRow],role:"alert",children:[jsx(PhosphorIcon,{size:"small",icon:infoIcon,color:semanticColor.core.foreground.critical.default,"aria-hidden":"true"}),jsx(BodyText,{tag:"span",style:modules_24b959f9.errorText,children:error})]})};const monthsShort=React.useMemo(()=>{const format=new Intl.DateTimeFormat(locale??navigator.language,{month:"short"}).format;return [...Array(12).keys()].map(m=>format(new Date(2021,m,15)))},[locale]);const renderMonth=()=>{return jsx(SingleSelect,{"aria-label":labels.month,"aria-invalid":!!error,error:!!error,disabled:disabled,placeholder:labels.month,onChange:handleMonthChange,selectedValue:month,style:[getMonthYearStyle(monthYearOnly),modules_24b959f9.input,dropdownStyle],testId:"birthday-picker-month",children:monthsShort.map((monthShort,i)=>jsx(OptionItem,{label:monthShort,value:String(i+1)},monthShort))})};const maybeRenderDay=()=>{if(monthYearOnly){return null}return jsx(SingleSelect,{"aria-label":labels.day,"aria-invalid":!!error,error:!!error,disabled:disabled,placeholder:labels.day,onChange:handleDayChange,selectedValue:day,style:[modules_24b959f9.fieldDay,modules_24b959f9.input,dropdownStyle],testId:"birthday-picker-day",children:Array.from(Array(31)).map((_,day)=>jsx(OptionItem,{label:String(day+1),value:String(day+1)},String(day+1)))})};const renderYear=()=>{return jsx(SingleSelect,{"aria-label":labels.year,"aria-invalid":!!error,error:!!error,disabled:disabled,placeholder:labels.year,onChange:handleYearChange,selectedValue:year,style:[getMonthYearStyle(monthYearOnly),modules_24b959f9.input,dropdownStyle],dropdownStyle:{minWidth:150},testId:"birthday-picker-year",children:Array.from(Array(120)).map((_,yearOffset)=>jsx(OptionItem,{label:String(CUR_YEAR-yearOffset),value:String(CUR_YEAR-yearOffset)},String(CUR_YEAR-yearOffset)))})};return jsxs(Fragment,{children:[jsxs(View,{testId:"birthday-picker",style:[modules_24b959f9.root,modules_24b959f9.wrapper,style],children:[renderMonth(),maybeRenderDay(),renderYear()]}),maybeRenderError()]})};var BirthdayPicker$1 = BirthdayPicker;
|
|
15
|
+
|
|
16
|
+
export { BirthdayPicker$1 as default };
|
|
17
|
+
|
|
18
|
+
import "./index.css";
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
@layer shared {/**
|
|
2
|
+
* BirthdayPicker styles
|
|
3
|
+
*
|
|
4
|
+
* Every rule is nested inside `.root`, a marker class that carries no
|
|
5
|
+
* declarations of its own. It sits on both top-level elements (the row of
|
|
6
|
+
* selects and the error row), which are `View`s. The selects' `style` lands
|
|
7
|
+
* on `SingleSelect`'s wrapper `View` (`DropdownCore`'s `menuWrapper`), and the
|
|
8
|
+
* error text is a `BodyText`. All of those ship rules in the same
|
|
9
|
+
* `@layer shared` that set properties overridden below (`flex-direction`,
|
|
10
|
+
* `min-inline-size`, `margin`, …). The bundle loads this package's CSS before
|
|
11
|
+
* its dependencies', so the compound selectors make these rules win on
|
|
12
|
+
* specificity rather than load order.
|
|
13
|
+
*
|
|
14
|
+
* The small-screen `@media` block comes last and its declarations are
|
|
15
|
+
* `!important`. On small screens the full-width, stacked layout must win over
|
|
16
|
+
* the consumer's `style` / `dropdownStyle` (and over the selects' minimum
|
|
17
|
+
* widths), while on larger screens the consumer's overrides win. The
|
|
18
|
+
* consumer's overrides are unlayered and `!important`, and only an
|
|
19
|
+
* `!important` declaration inside a cascade layer outranks those.
|
|
20
|
+
*
|
|
21
|
+
* Outside that block, the consumer's `style` and `dropdownStyle` (unlayered
|
|
22
|
+
* and `!important`) win over this module. The build wraps
|
|
23
|
+
* every rule in `@layer shared { … }`.
|
|
24
|
+
*/.wb-birthday-picker-root-6784a980 {
|
|
25
|
+
&.wb-birthday-picker-wrapper-6784a980 {
|
|
26
|
+
flex-direction: row;
|
|
27
|
+
gap: var(--wb-sizing-size_080);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* Minimum widths of the selects. */
|
|
31
|
+
|
|
32
|
+
/* Month and year when the full date of birth is shown. */
|
|
33
|
+
& .wb-birthday-picker-fieldFull-6784a980 {
|
|
34
|
+
min-inline-size: 110px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* Month and year when the day field is hidden (`monthYearOnly`).
|
|
38
|
+
* See: https://www.figma.com/file/uJZi9ZvuEz5N8GJ3HqKFAa/(2021)-Account-records?node-id=20%3A398 */
|
|
39
|
+
& .wb-birthday-picker-fieldMonthYear-6784a980 {
|
|
40
|
+
min-inline-size: 167px;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
& .wb-birthday-picker-fieldDay-6784a980 {
|
|
44
|
+
min-inline-size: 100px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&.wb-birthday-picker-errorRow-6784a980 {
|
|
48
|
+
flex-direction: row;
|
|
49
|
+
place-items: center;
|
|
50
|
+
gap: var(--wb-sizing-size_040);
|
|
51
|
+
margin-block-start: var(--wb-sizing-size_040);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
& .wb-birthday-picker-errorText-6784a980 {
|
|
55
|
+
color: var(--wb-semanticColor-core-foreground-critical-default);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* breakpoint.mediaQuery.xsOrSmaller (max-width: breakpoint.width.xsMax) */
|
|
59
|
+
@media screen and (max-width: 567px) {
|
|
60
|
+
&.wb-birthday-picker-wrapper-6784a980 {
|
|
61
|
+
flex-direction: column !important;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
& .wb-birthday-picker-input-6784a980 {
|
|
65
|
+
min-inline-size: 100% !important;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/*# sourceMappingURL=index.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["<no source>","../src/components/birthday-picker.module.css"],"names":[],"mappings":"AAAA,eCAA;;;;;;;;;;;;;;;;;;;;;;;EAuBE,CAEF;IACI;QACI,mBAAmB;QACnB,8BAA8B;IAClC;;IAEA,mCAAmC;;IAEnC,yDAAyD;IACzD;QACI,sBAAsB;IAC1B;;IAEA;uGACmG;IACnG;QACI,sBAAsB;IAC1B;;IAEA;QACI,sBAAsB;IAC1B;;IAEA;QACI,mBAAmB;QACnB,mBAAmB;QACnB,8BAA8B;QAC9B,6CAA6C;IACjD;;IAEA;QACI,+DAA+D;IACnE;;IAEA,0EAA0E;IAC1E;QACI;YACI,iCAAiC;QACrC;;QAEA;YACI,gCAAgC;QACpC;IACJ;AACJ;CDrEA","file":"index.css","sourcesContent":[null,"/**\n * BirthdayPicker styles\n *\n * Every rule is nested inside `.root`, a marker class that carries no\n * declarations of its own. It sits on both top-level elements (the row of\n * selects and the error row), which are `View`s. The selects' `style` lands\n * on `SingleSelect`'s wrapper `View` (`DropdownCore`'s `menuWrapper`), and the\n * error text is a `BodyText`. All of those ship rules in the same\n * `@layer shared` that set properties overridden below (`flex-direction`,\n * `min-inline-size`, `margin`, …). The bundle loads this package's CSS before\n * its dependencies', so the compound selectors make these rules win on\n * specificity rather than load order.\n *\n * The small-screen `@media` block comes last and its declarations are\n * `!important`. On small screens the full-width, stacked layout must win over\n * the consumer's `style` / `dropdownStyle` (and over the selects' minimum\n * widths), while on larger screens the consumer's overrides win. The\n * consumer's overrides are unlayered and `!important`, and only an\n * `!important` declaration inside a cascade layer outranks those.\n *\n * Outside that block, the consumer's `style` and `dropdownStyle` (unlayered\n * and `!important`) win over this module. The build wraps\n * every rule in `@layer shared { … }`.\n */\n\n.root {\n &.wrapper {\n flex-direction: row;\n gap: var(--wb-sizing-size_080);\n }\n\n /* Minimum widths of the selects. */\n\n /* Month and year when the full date of birth is shown. */\n & .fieldFull {\n min-inline-size: 110px;\n }\n\n /* Month and year when the day field is hidden (`monthYearOnly`).\n * See: https://www.figma.com/file/uJZi9ZvuEz5N8GJ3HqKFAa/(2021)-Account-records?node-id=20%3A398 */\n & .fieldMonthYear {\n min-inline-size: 167px;\n }\n\n & .fieldDay {\n min-inline-size: 100px;\n }\n\n &.errorRow {\n flex-direction: row;\n place-items: center;\n gap: var(--wb-sizing-size_040);\n margin-block-start: var(--wb-sizing-size_040);\n }\n\n & .errorText {\n color: var(--wb-semanticColor-core-foreground-critical-default);\n }\n\n /* breakpoint.mediaQuery.xsOrSmaller (max-width: breakpoint.width.xsMax) */\n @media (--wb-breakpoint-mediaQuery-xsOrSmaller) {\n &.wrapper {\n flex-direction: column !important;\n }\n\n & .input {\n min-inline-size: 100% !important;\n }\n }\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var temporalPolyfill = require('temporal-polyfill');
|
|
5
5
|
var React = require('react');
|
|
6
|
-
var aphrodite = require('aphrodite');
|
|
7
6
|
var wonderBlocksConfig = require('@khanacademy/wonder-blocks-config');
|
|
8
7
|
var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
|
|
9
8
|
var wonderBlocksTokens = require('@khanacademy/wonder-blocks-tokens');
|
|
@@ -35,6 +34,10 @@ function _interopNamespace(e) {
|
|
|
35
34
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
36
35
|
var infoIcon__default = /*#__PURE__*/_interopDefaultLegacy(infoIcon);
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
var modules_24b959f9={"root":"wb-birthday-picker-root-6784a980","wrapper":"wb-birthday-picker-wrapper-6784a980","fieldFull":"wb-birthday-picker-fieldFull-6784a980","fieldMonthYear":"wb-birthday-picker-fieldMonthYear-6784a980","fieldDay":"wb-birthday-picker-fieldDay-6784a980","errorRow":"wb-birthday-picker-errorRow-6784a980","errorText":"wb-birthday-picker-errorText-6784a980","input":"wb-birthday-picker-input-6784a980"};
|
|
39
38
|
|
|
40
|
-
|
|
39
|
+
const CUR_YEAR=new Date().getYear()+1900;const isFutureDate=date=>{return temporalPolyfill.Temporal.PlainDate.compare(date,temporalPolyfill.Temporal.Now.plainDateISO())===1};const getStateFromDefault=(defaultValue,monthYearOnly,labels)=>{const initialState={month:null,day:monthYearOnly?"1":null,year:null,error:null};if(defaultValue){let date=null;try{date=temporalPolyfill.Temporal.PlainDate.from(defaultValue);}catch(err){initialState.error=labels.errorMessage;return initialState}if(monthYearOnly){date=date.with({day:date.daysInMonth});}initialState.month=String(date.month);initialState.day=String(date.day);initialState.year=String(date.year);if(isFutureDate(date)){initialState.error=labels.errorMessage;}}return initialState};const getMonthYearStyle=monthYearOnly=>monthYearOnly?modules_24b959f9.fieldMonthYear:modules_24b959f9.fieldFull;const BirthdayPicker=props=>{const{defaultValue,disabled,dropdownStyle,locale,monthYearOnly,onChange,style}=props;const{strings}=wonderBlocksConfig.useWonderBlocksI18n();const labelsRef=React__namespace.useRef({errorMessage:props.labels?.errorMessage||strings.birthdateErrorMessage,month:props.labels?.month||strings.fieldLabelMonth,year:props.labels?.year||strings.fieldLabelYear,day:props.labels?.day||strings.fieldLabelDay});const labels=labelsRef.current;const[initialState]=React__namespace.useState(()=>getStateFromDefault(defaultValue,monthYearOnly,labels));const[month,setMonth]=React__namespace.useState(initialState.month);const[day,setDay]=React__namespace.useState(initialState.day);const[year,setYear]=React__namespace.useState(initialState.year);const[error,setError]=React__namespace.useState(initialState.error);const valuesRef=React__namespace.useRef({month:initialState.month,day:initialState.day,year:initialState.year});const lastChangeValueRef=React__namespace.useRef(defaultValue||null);const reportChange=React__namespace.useCallback(value=>{if(value!==lastChangeValueRef.current){lastChangeValueRef.current=value;onChange(value);}},[onChange]);const handleChange=React__namespace.useCallback(()=>{const{month,day,year}=valuesRef.current;const dateFields=[year,month];if(!monthYearOnly){dateFields.push(day);}if(dateFields.some(field=>field===null)){reportChange(null);return}let date;try{if(monthYearOnly){date=temporalPolyfill.Temporal.PlainDate.from({year:Number(year),month:Number(month),day:31});}else {date=temporalPolyfill.Temporal.PlainDate.from({year:Number(year),month:Number(month),day:Number(day)},{overflow:"reject"});}}catch(err){setError(labels.errorMessage);reportChange(null);return}if(isFutureDate(date)){setError(labels.errorMessage);reportChange(null);}else {setError(null);reportChange(date.toString());}},[labels,monthYearOnly,reportChange]);const handleMonthChange=React__namespace.useCallback(month=>{valuesRef.current={...valuesRef.current,month};setMonth(month);handleChange();},[handleChange]);const handleDayChange=React__namespace.useCallback(day=>{valuesRef.current={...valuesRef.current,day};setDay(day);handleChange();},[handleChange]);const handleYearChange=React__namespace.useCallback(year=>{valuesRef.current={...valuesRef.current,year};setYear(year);handleChange();},[handleChange]);const maybeRenderError=()=>{if(!error){return null}return jsxRuntime.jsxs(wonderBlocksCore.View,{style:[modules_24b959f9.root,modules_24b959f9.errorRow],role:"alert",children:[jsxRuntime.jsx(wonderBlocksIcon.PhosphorIcon,{size:"small",icon:infoIcon__default["default"],color:wonderBlocksTokens.semanticColor.core.foreground.critical.default,"aria-hidden":"true"}),jsxRuntime.jsx(wonderBlocksTypography.BodyText,{tag:"span",style:modules_24b959f9.errorText,children:error})]})};const monthsShort=React__namespace.useMemo(()=>{const format=new Intl.DateTimeFormat(locale??navigator.language,{month:"short"}).format;return [...Array(12).keys()].map(m=>format(new Date(2021,m,15)))},[locale]);const renderMonth=()=>{return jsxRuntime.jsx(wonderBlocksDropdown.SingleSelect,{"aria-label":labels.month,"aria-invalid":!!error,error:!!error,disabled:disabled,placeholder:labels.month,onChange:handleMonthChange,selectedValue:month,style:[getMonthYearStyle(monthYearOnly),modules_24b959f9.input,dropdownStyle],testId:"birthday-picker-month",children:monthsShort.map((monthShort,i)=>jsxRuntime.jsx(wonderBlocksDropdown.OptionItem,{label:monthShort,value:String(i+1)},monthShort))})};const maybeRenderDay=()=>{if(monthYearOnly){return null}return jsxRuntime.jsx(wonderBlocksDropdown.SingleSelect,{"aria-label":labels.day,"aria-invalid":!!error,error:!!error,disabled:disabled,placeholder:labels.day,onChange:handleDayChange,selectedValue:day,style:[modules_24b959f9.fieldDay,modules_24b959f9.input,dropdownStyle],testId:"birthday-picker-day",children:Array.from(Array(31)).map((_,day)=>jsxRuntime.jsx(wonderBlocksDropdown.OptionItem,{label:String(day+1),value:String(day+1)},String(day+1)))})};const renderYear=()=>{return jsxRuntime.jsx(wonderBlocksDropdown.SingleSelect,{"aria-label":labels.year,"aria-invalid":!!error,error:!!error,disabled:disabled,placeholder:labels.year,onChange:handleYearChange,selectedValue:year,style:[getMonthYearStyle(monthYearOnly),modules_24b959f9.input,dropdownStyle],dropdownStyle:{minWidth:150},testId:"birthday-picker-year",children:Array.from(Array(120)).map((_,yearOffset)=>jsxRuntime.jsx(wonderBlocksDropdown.OptionItem,{label:String(CUR_YEAR-yearOffset),value:String(CUR_YEAR-yearOffset)},String(CUR_YEAR-yearOffset)))})};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(wonderBlocksCore.View,{testId:"birthday-picker",style:[modules_24b959f9.root,modules_24b959f9.wrapper,style],children:[renderMonth(),maybeRenderDay(),renderYear()]}),maybeRenderError()]})};var BirthdayPicker$1 = BirthdayPicker;
|
|
40
|
+
|
|
41
|
+
module.exports = BirthdayPicker$1;
|
|
42
|
+
|
|
43
|
+
require("./index.css");
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "",
|
|
4
4
|
"author": "Khan Academy",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "
|
|
6
|
+
"version": "5.0.0",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -19,18 +19,32 @@
|
|
|
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
|
+
],
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/es/index.js",
|
|
29
|
+
"require": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./css": {
|
|
32
|
+
"import": "./dist/es/index.css",
|
|
33
|
+
"require": "./dist/index.css",
|
|
34
|
+
"default": "./dist/index.css"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
22
37
|
"dependencies": {
|
|
23
38
|
"@khanacademy/wonder-blocks-config": "0.7.1",
|
|
24
|
-
"@khanacademy/wonder-blocks-core": "
|
|
25
|
-
"@khanacademy/wonder-blocks-dropdown": "
|
|
26
|
-
"@khanacademy/wonder-blocks-icon": "
|
|
27
|
-
"@khanacademy/wonder-blocks-layout": "
|
|
28
|
-
"@khanacademy/wonder-blocks-tokens": "18.
|
|
29
|
-
"@khanacademy/wonder-blocks-typography": "
|
|
39
|
+
"@khanacademy/wonder-blocks-core": "13.0.0",
|
|
40
|
+
"@khanacademy/wonder-blocks-dropdown": "12.0.0",
|
|
41
|
+
"@khanacademy/wonder-blocks-icon": "7.0.0",
|
|
42
|
+
"@khanacademy/wonder-blocks-layout": "5.0.0",
|
|
43
|
+
"@khanacademy/wonder-blocks-tokens": "18.3.0",
|
|
44
|
+
"@khanacademy/wonder-blocks-typography": "6.0.0"
|
|
30
45
|
},
|
|
31
46
|
"peerDependencies": {
|
|
32
47
|
"@phosphor-icons/core": "^2.0.2",
|
|
33
|
-
"aphrodite": "^1.2.5",
|
|
34
48
|
"temporal-polyfill": "^0.3.0",
|
|
35
49
|
"react": "18.2.0"
|
|
36
50
|
},
|