@sproutsocial/seeds-react-datepicker 1.0.51 → 1.1.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.
@@ -0,0 +1,262 @@
1
+ /**
2
+ * Seeds Datepicker component classes
3
+ *
4
+ * Requires @sproutsocial/seeds-react-theme/dist/theme-all.css imported for
5
+ * CSS variable definitions and dark mode support.
6
+ *
7
+ * This file has two halves, and they are deliberately in different cascade
8
+ * positions.
9
+ *
10
+ *
11
+ * 1. react-dates overrides — UNLAYERED (approved exception)
12
+ * ---------------------------------------------------------------------------
13
+ * The block below restyles react-dates' own DOM. It is the static port of the
14
+ * `ReactDatesCssOverrides` createGlobalStyle in styles.ts, which used to be
15
+ * injected at runtime whenever a picker mounted.
16
+ *
17
+ * It is emitted OUTSIDE `@layer components`, which is an explicit, approved
18
+ * exception to the repository's Tailwind delivery convention. react-dates ships
19
+ * `react-dates/lib/css/_datepicker.css` with zero cascade layers, and an
20
+ * unlayered declaration beats every layered one no matter how specific. A
21
+ * layered port would silently lose the .DayPicker__horizontal box-shadow reset,
22
+ * the .CalendarDay__default color and hover reset, and the .CalendarMonth_caption
23
+ * padding — only the one !important rule would survive.
24
+ *
25
+ * Two unlayered rules of equal specificity fall back to source order, and a
26
+ * consuming bundler decides whether this file lands before or after
27
+ * _datepicker.css. So every override that contests a react-dates declaration is
28
+ * qualified with the .DayPicker ancestor (or, for the root element itself, with
29
+ * its own base class), which outranks react-dates' plain single-class rules
30
+ * whatever the stylesheet order.
31
+ *
32
+ * react-dates ALSO ships pseudo-class rules — .CalendarDay__default:hover and
33
+ * .CalendarDay__selected:hover among them — and a pseudo-class counts toward the
34
+ * same specificity component as a class, so those sit at (0,2,0) and tie with a
35
+ * plain .DayPicker-qualified override. That is why the two CalendarDay :hover
36
+ * variants below are written out at (0,3,0). They are load-bearing, NOT redundant
37
+ * copies of their base rules: delete them and the hover background and border
38
+ * resets become stylesheet-order-dependent again.
39
+ *
40
+ * The nav-button :hover rule is different. It is simply the hover state carried
41
+ * over from the styled implementation. react-dates ships no rule for
42
+ * .DayPickerNavigation_button__horizontal at all, only __horizontalDefault at
43
+ * (0,1,0), and its .DayPickerNavigation_button__default rules never apply here
44
+ * because Seeds always supplies navPrev and navNext, so react-dates marks the
45
+ * buttons non-default. Nothing contests it.
46
+ *
47
+ * NOT covered: react-dates' :active variants — .CalendarDay__selected:active and
48
+ * its blocked, hovered_span and highlighted_calendar siblings — also sit at
49
+ * (0,2,0) and therefore TIE with the overrides below, leaving the winner to
50
+ * stylesheet order in the consuming bundle. The styled implementation's
51
+ * unqualified single-class rules lost those contests outright, so this is
52
+ * same-or-better everywhere and never a regression, but a pressed day may still
53
+ * flash react-dates' own palette. Closing it means adding
54
+ * .DayPicker .CalendarDay:active to the transparent-background group and
55
+ * .DayPicker .CalendarDay__default:active to the border-reset group, which is a
56
+ * deliberate visual change and was not authorized for Phase A.
57
+ *
58
+ * The magic numbers are carried over verbatim from the styled implementation.
59
+ * They are tuned against react-dates' own layout — do not "normalize" them to
60
+ * theme tokens. In particular `line-height: 21.333px` is NOT --line-height-200,
61
+ * and `top: 26px` on the week header is still a magic number aligning it with
62
+ * .CalendarMonth_caption.
63
+ *
64
+ * One magic number was deliberately NOT carried over: `width: 230px` on the week
65
+ * header, along with the two rules that compensated for it. It assumed
66
+ * content-box and broke once Tailwind's preflight made everything border-box.
67
+ * The header now shrink-wraps to the month. See the comment on that rule.
68
+ *
69
+ *
70
+ * 2. Day cell — LAYERED, as usual
71
+ * ---------------------------------------------------------------------------
72
+ * `.seeds-datepicker-day*` styles a node this package renders itself, so it
73
+ * follows the normal convention and lives in `@layer components`, letting
74
+ * consumer Tailwind utilities override it.
75
+ *
76
+ * Usage (applied by CalendarDayTailwind.tsx):
77
+ * <div class="seeds-datepicker-day seeds-datepicker-day-selected
78
+ * seeds-datepicker-day-pill-left">17</div>
79
+ */
80
+
81
+ /* ========================================================================== */
82
+ /* react-dates overrides (unlayered — see note 1 above) */
83
+ /* ========================================================================== */
84
+
85
+ /* The one override left unqualified, at (0,1,0). It therefore ties with
86
+ react-dates' own `.DayPicker` rule and the winner is load order — where the
87
+ styled version, injected last at runtime, always won. Harmless today because
88
+ the two declaration sets are disjoint (this rule sets box-sizing, font-weight
89
+ and font-family; react-dates sets background, position and text-align), so
90
+ there is nothing to contest. Qualify it as `.DayPicker.DayPicker` if react-dates
91
+ ever adds one of these properties. */
92
+ .DayPicker {
93
+ box-sizing: content-box;
94
+ font-weight: var(--font-weight-normal);
95
+ font-family: var(--font-family);
96
+ }
97
+
98
+ /* Override react-dates' height to better reflect how tall the component
99
+ actually is. Adding margin/padding is truer to the Seeds system, because the
100
+ calendar height adds an extra row of padding if we do not override it.
101
+ !important is required because react-dates sets height on the element. */
102
+ .DayPicker .DayPicker_transitionContainer {
103
+ height: 228px !important;
104
+ }
105
+
106
+ /* No `width` here on purpose. The styled implementation pinned `width: 230px`
107
+ to stretch the underline the full month width, which only held while the
108
+ element was content-box. Tailwind's preflight sets `* { box-sizing:
109
+ border-box }`, so react-dates' own inline `padding: 0 13px` started
110
+ subtracting from that 230px: 230 - 26 - 10 = 194px of content against the
111
+ 7 x 30px = 210px the day columns need, which wrapped Saturday onto a second
112
+ line and dropped the border-bottom through the first row of dates. Letting
113
+ the header shrink-wrap to the month makes it track `daySize` instead of a
114
+ magic number, and gives the same result under either box-sizing.
115
+ Deleting the width also means react-dates' own `.DayPicker_weekHeaders__horizontal`
116
+ margin-left and `.DayPicker_weekHeader_ul` padding-left must be left alone —
117
+ the styled version overrode both to compensate for the pinned width. */
118
+ .DayPicker .DayPicker_weekHeader {
119
+ color: var(--color-text-headline);
120
+ border-bottom: 1px solid var(--color-container-border-base);
121
+
122
+ /* Magic number to match position of .CalendarMonth_caption */
123
+ top: 26px;
124
+ }
125
+
126
+ .DayPicker .DayPicker_weekHeader_li {
127
+ font-size: var(--font-size-200);
128
+ line-height: var(--line-height-200);
129
+ color: var(--color-text-subtext);
130
+ font-weight: var(--font-weight-semibold);
131
+ margin: 0;
132
+ }
133
+
134
+ .DayPicker.DayPicker__horizontal {
135
+ box-shadow: none;
136
+ background: var(--color-container-bg-base);
137
+ }
138
+
139
+ .DayPicker .CalendarDay {
140
+ background-color: transparent;
141
+ }
142
+
143
+ .DayPicker .CalendarDay__selected,
144
+ .DayPicker .CalendarDay__selected_span,
145
+ .DayPicker .CalendarDay:hover {
146
+ background-color: transparent;
147
+ }
148
+
149
+ .DayPicker .CalendarDay__default,
150
+ .DayPicker .CalendarDay__default:hover {
151
+ border: none;
152
+ color: var(--color-text-body);
153
+ }
154
+
155
+ .DayPicker .CalendarMonth {
156
+ font-size: var(--font-size-200);
157
+ line-height: var(--line-height-200);
158
+ background: var(--color-container-bg-base);
159
+
160
+ /* spacing between visible months and months off canvas */
161
+ padding: 0 15px;
162
+ }
163
+
164
+ .DayPicker .CalendarMonth_caption {
165
+ font-size: var(--font-size-200);
166
+ line-height: var(--line-height-200);
167
+ color: var(--color-text-headline);
168
+ padding-top: 0;
169
+ background: var(--color-container-bg-base);
170
+ }
171
+
172
+ .DayPicker .CalendarMonth_caption strong {
173
+ font-weight: var(--font-weight-semibold);
174
+ }
175
+
176
+ .DayPicker .CalendarMonth_table {
177
+ line-height: 21.333px;
178
+ }
179
+
180
+ .DayPicker .CalendarMonth_table tr {
181
+ vertical-align: middle;
182
+ }
183
+
184
+ .DayPicker .CalendarMonth_table td {
185
+ padding: 0;
186
+ border-bottom: none;
187
+ }
188
+
189
+ .DayPicker .CalendarMonthGrid {
190
+ background: var(--color-container-bg-base);
191
+ }
192
+
193
+ /* Left and Right Arrow Buttons to navigate months */
194
+ .DayPicker .DayPickerNavigation_button__horizontal {
195
+ color: var(--color-button-pill-text-base);
196
+ top: -4px;
197
+ padding: 7px 8px;
198
+ position: absolute;
199
+ line-height: 0.78;
200
+ border-radius: 9999px;
201
+ border: none;
202
+ background: var(--color-button-pill-bg-base);
203
+ }
204
+
205
+ .DayPicker .DayPickerNavigation_button__horizontal:nth-child(1) {
206
+ left: 22px;
207
+ }
208
+
209
+ .DayPicker .DayPickerNavigation_button__horizontal:nth-child(2) {
210
+ right: 22px;
211
+ }
212
+
213
+ .DayPicker .DayPickerNavigation_button__horizontal:hover {
214
+ background: var(--color-button-pill-bg-hover);
215
+ }
216
+
217
+ /* ========================================================================== */
218
+ /* Day cell (layered — see note 2 above) */
219
+ /* ========================================================================== */
220
+
221
+ @layer components {
222
+ /* Baseline inherited from Box, which the legacy day cell extended. Box ships
223
+ no CSS of its own, so the static cell has to reproduce it here. */
224
+ .seeds-datepicker-day {
225
+ box-sizing: border-box;
226
+ font-family: var(--font-family);
227
+ }
228
+
229
+ .seeds-datepicker-day-selected {
230
+ background-color: var(--color-container-bg-selected);
231
+ color: var(--color-text-inverse);
232
+ }
233
+
234
+ /* The pill edges are separate classes on purpose. The legacy implementation
235
+ interpolated `margin-left: ${condition && space}`, which emits NO
236
+ declaration when the condition is false — writing a `0` fallback here would
237
+ square off the ends of every selected range. */
238
+ .seeds-datepicker-day-pill-left {
239
+ margin-left: var(--space-200);
240
+ border-top-left-radius: var(--radius-pill);
241
+ border-bottom-left-radius: var(--radius-pill);
242
+ }
243
+
244
+ .seeds-datepicker-day-pill-right {
245
+ margin-right: var(--space-200);
246
+ border-top-right-radius: var(--radius-pill);
247
+ border-bottom-right-radius: var(--radius-pill);
248
+ }
249
+
250
+ .seeds-datepicker-day-hovered {
251
+ margin: 0 var(--space-200);
252
+ border-radius: var(--radius-pill);
253
+ border: 1px solid var(--color-container-border-selected);
254
+ }
255
+
256
+ /* Mirrors the `disabled` mixin from seeds-react-mixins. */
257
+ .seeds-datepicker-day-out-of-range {
258
+ color: var(--color-text-subtext);
259
+ opacity: 0.4;
260
+ pointer-events: none;
261
+ }
262
+ }
@@ -0,0 +1,71 @@
1
+ import moment from "moment";
2
+ import type { ModifiersShape } from "react-dates";
3
+
4
+ /*
5
+ * Partial list of modifiers given to renderDayContents by airbnb/react-dates. There may be more.
6
+ *
7
+ * today, blocked, blocked-calendar, blocked-out-of-range, highlighted-calendar, valid,
8
+ * selected, selected-start, selected-end, blocked-minimum-nights, selected-span, last-in-range,
9
+ * hovered, hovered-span, hovered-offset, after-hovered-start, first-day-of-week, last-day-of-week,
10
+ * hovered-start-first-possible-end, hovered-start-blocked-minimum-nights, before-hovered-end,
11
+ * no-selected-start-before-selected-end, selected-start-in-hovered-span, selected-start-no-selected-end,
12
+ * selected-end-no-selected-start
13
+ *
14
+ * These predicates are the single source of truth for which visual state a day
15
+ * cell is in. Both the static day cell (CalendarDayTailwind) and the preserved
16
+ * styled one (styles.ts) read them, so the two paths cannot drift apart.
17
+ */
18
+
19
+ export const isSelected = (modifiers: ModifiersShape) =>
20
+ modifiers.has("selected-span") ||
21
+ modifiers.has("selected") ||
22
+ modifiers.has("selected-start") ||
23
+ modifiers.has("selected-end") ||
24
+ modifiers.has("hovered-span") ||
25
+ modifiers.has("after-hovered-start");
26
+
27
+ export const isOutOfRange = (modifiers: ModifiersShape) =>
28
+ modifiers.has("blocked-out-of-range");
29
+
30
+ export const isHoveredAndInRange = (modifiers: ModifiersShape) =>
31
+ modifiers.has("hovered") && !modifiers.has("blocked-out-of-range");
32
+
33
+ export const shouldHaveLeftPill = (
34
+ modifiers: ModifiersShape,
35
+ day: moment.Moment
36
+ ) => {
37
+ if (!isSelected(modifiers)) {
38
+ return false;
39
+ }
40
+
41
+ if (
42
+ modifiers.has("selected") ||
43
+ modifiers.has("selected-start") ||
44
+ modifiers.has("first-day-of-week") ||
45
+ day.isSame(moment(day).startOf("month"), "day")
46
+ ) {
47
+ return true;
48
+ }
49
+
50
+ return false;
51
+ };
52
+
53
+ export const shouldHaveRightPill = (
54
+ modifiers: ModifiersShape,
55
+ day: moment.Moment
56
+ ) => {
57
+ if (!isSelected(modifiers)) {
58
+ return false;
59
+ }
60
+
61
+ if (
62
+ modifiers.has("selected") ||
63
+ modifiers.has("selected-end") ||
64
+ modifiers.has("last-day-of-week") ||
65
+ day.isSame(moment(day).endOf("month"), "day")
66
+ ) {
67
+ return true;
68
+ }
69
+
70
+ return false;
71
+ };
package/src/styles.ts CHANGED
@@ -3,65 +3,32 @@ import moment from "moment";
3
3
  import type { ModifiersShape } from "react-dates";
4
4
  import { disabled } from "@sproutsocial/seeds-react-mixins";
5
5
  import Box from "@sproutsocial/seeds-react-box";
6
+ import {
7
+ isHoveredAndInRange,
8
+ isOutOfRange,
9
+ isSelected,
10
+ shouldHaveLeftPill,
11
+ shouldHaveRightPill,
12
+ } from "./dayModifiers";
6
13
 
7
14
  /*
8
- * Partial list of modifiers given to renderDayContents by airbnb/react-dates. There may be more.
15
+ * PHASE A NOTE this module is the legacy styled-components implementation.
9
16
  *
10
- * today, blocked, blocked-calendar, blocked-out-of-range, highlighted-calendar, valid,
11
- * selected, selected-start, selected-end, blocked-minimum-nights, selected-span, last-in-range,
12
- * hovered, hovered-span, hovered-offset, after-hovered-start, first-day-of-week, last-day-of-week,
13
- * hovered-start-first-possible-end, hovered-start-blocked-minimum-nights, before-hovered-end,
14
- * no-selected-start-before-selected-end, selected-start-in-hovered-span, selected-start-no-selected-end,
15
- * selected-end-no-selected-start
17
+ * Nothing imports it any more: the day cell is rendered by CalendarDayTailwind
18
+ * and the react-dates overrides ship statically from datepicker.css. It is
19
+ * unreachable from src/index.ts and is tree-shaken out of dist. It is kept at
20
+ * source because Phase A does not remove styled-components, and because the
21
+ * permanent contract tests use it as the reference implementation the static
22
+ * path must match.
16
23
  *
24
+ * The state predicates now live in ./dayModifiers so that this implementation
25
+ * and the static one cannot drift apart.
26
+ *
27
+ * Consequently the shipped bundle no longer uses seeds-react-box or
28
+ * seeds-react-mixins (still in `dependencies`) or styled-components (still a
29
+ * peer). That is correct for Phase A — this module still needs them at source —
30
+ * and is a Phase B cleanup item.
17
31
  */
18
- const isSelected = (modifiers: ModifiersShape) =>
19
- modifiers.has("selected-span") ||
20
- modifiers.has("selected") ||
21
- modifiers.has("selected-start") ||
22
- modifiers.has("selected-end") ||
23
- modifiers.has("hovered-span") ||
24
- modifiers.has("after-hovered-start");
25
-
26
- const isOutOfRange = (modifiers: ModifiersShape) =>
27
- modifiers.has("blocked-out-of-range");
28
-
29
- const isHoveredAndInRange = (modifiers: ModifiersShape) =>
30
- modifiers.has("hovered") && !modifiers.has("blocked-out-of-range");
31
-
32
- const shouldHaveLeftPill = (modifiers: ModifiersShape, day: moment.Moment) => {
33
- if (!isSelected(modifiers)) {
34
- return false;
35
- }
36
-
37
- if (
38
- modifiers.has("selected") ||
39
- modifiers.has("selected-start") ||
40
- modifiers.has("first-day-of-week") ||
41
- day.isSame(moment(day).startOf("month"), "day")
42
- ) {
43
- return true;
44
- }
45
-
46
- return false;
47
- };
48
-
49
- const shouldHaveRightPill = (modifiers: ModifiersShape, day: moment.Moment) => {
50
- if (!isSelected(modifiers)) {
51
- return false;
52
- }
53
-
54
- if (
55
- modifiers.has("selected") ||
56
- modifiers.has("selected-end") ||
57
- modifiers.has("last-day-of-week") ||
58
- day.isSame(moment(day).endOf("month"), "day")
59
- ) {
60
- return true;
61
- }
62
-
63
- return false;
64
- };
65
32
 
66
33
  export const CalendarDay = styled(Box)<{
67
34
  modifiers: ModifiersShape;