@automattic/date-range-picker 1.0.0 → 1.0.2

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 ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ ## 1.0.2
4
+
5
+ - Packaging: pre-compile SCSS to CSS in `dist/{esm,cjs}/style.css` so external consumers no longer need a Sass loader. SCSS variables from `@wordpress/base-styles` are resolved at build time.
6
+ - Packaging: move `@wordpress/components`, `@wordpress/compose`, `@wordpress/date`, `@wordpress/i18n`, and `@wordpress/icons` to `peerDependencies` (with `>=` ranges) to prevent duplicate installs and to accommodate hosts pinned to newer `@wordpress/*` majors.
7
+ - Packaging: stop shipping `src/test/**` and `dist/*.tsbuildinfo` in the published tarball.
8
+ - Packaging: drop unused `tslib` runtime dependency.
9
+ - Styles: add sensible fallbacks (`#fff`, `#1e1e1e`, `#949494`) to the dashboard CSS custom properties so the picker renders correctly outside the Calypso dashboard shell.
10
+ - Docs: add a "Using outside Calypso" section to the README documenting peer-deps, the required `@automattic/ui/style.css` import, and the themable CSS custom properties.
11
+
12
+ ## 1.0.1
13
+
14
+ - Fix packaging: include `style.scss` in `dist/esm/` and `dist/cjs/` so the compiled `import './style.scss'` resolves for consumers that don't use the `calypso:src` exports condition.
15
+
16
+ ## 1.0.0
17
+
18
+ - Initial release ([#110712](https://github.com/Automattic/wp-calypso/pull/110712))
package/README.md CHANGED
@@ -11,19 +11,6 @@ site-day handling.
11
11
  npm install @automattic/date-range-picker
12
12
  ```
13
13
 
14
- Consumers must also load the calendar styles from `@automattic/ui` and import
15
- the picker's own stylesheet. The package ships SCSS source; compile it via
16
- your own build pipeline (sass-loader, etc.):
17
-
18
- ```ts
19
- import '@automattic/ui/style.css';
20
- import '@automattic/date-range-picker/src/style.scss';
21
- ```
22
-
23
- The SCSS expects `$grid-unit-*`, `$radius-small`, and `$gray-600` from
24
- `@wordpress/base-styles` to be in scope (either via a global `@import` or via
25
- sass-loader's `additionalData`).
26
-
27
14
  ## Usage
28
15
 
29
16
  ```tsx
@@ -44,6 +31,11 @@ function Example() {
44
31
  }
45
32
  ```
46
33
 
34
+ The picker's stylesheet is side-effect imported from the component module, so a
35
+ plain `import { DateRangePicker }` is enough — there's no separate CSS import to
36
+ remember. The package ships pre-compiled CSS in `dist/`, so consumers don't
37
+ need a Sass loader.
38
+
47
39
  ### Props
48
40
 
49
41
  | Prop | Type | Default | Description |
@@ -73,6 +65,51 @@ import {
73
65
  } from '@automattic/date-range-picker';
74
66
  ```
75
67
 
68
+ ## Using outside Calypso
69
+
70
+ The package is published to npm and works for any React app — Jetpack, custom
71
+ WordPress plugins, etc. A few things to know:
72
+
73
+ ### Required peer dependencies
74
+
75
+ The host application must install these alongside the picker:
76
+
77
+ - `react` and `react-dom` (`^18.3.1`)
78
+ - `@wordpress/components` (`>=32.1.0`)
79
+ - `@wordpress/compose` (`>=7.23.0`)
80
+ - `@wordpress/date` (`>=5.23.0`)
81
+ - `@wordpress/i18n` (`>=5.23.0`)
82
+ - `@wordpress/icons` (`>=10.23.0`)
83
+
84
+ These are peer dependencies (not bundled) so that the host can control the
85
+ exact version and avoid duplicate copies of WordPress packages — multiple
86
+ copies of `@wordpress/compose` will silently break hooks shared across the
87
+ picker and the host.
88
+
89
+ ### Calendar styles
90
+
91
+ The picker renders `@automattic/ui`'s `DateRangeCalendar`. Make sure the
92
+ host loads its stylesheet once:
93
+
94
+ ```ts
95
+ import '@automattic/ui/style.css';
96
+ ```
97
+
98
+ ### Skinning via CSS custom properties
99
+
100
+ The picker honours these CSS custom properties on a wrapping element, with
101
+ sensible defaults when they're not set:
102
+
103
+ | Custom property | Default | Purpose |
104
+ | --------------------------------------- | ------------- | -------------------------------------- |
105
+ | `--dashboard-surface__background-color` | `#fff` | Trigger button background. |
106
+ | `--dashboard__text-color` | `#1e1e1e` | Trigger button text and icon colour. |
107
+ | `--dashboard-field__border-color` | `#949494` | Trigger button border colour. |
108
+
109
+ Set them on `:root` (or any ancestor of the picker) to theme it. The Calypso
110
+ dashboard shell sets these globally; outside Calypso, set whichever you'd like
111
+ to override.
112
+
76
113
  ## Translations
77
114
 
78
115
  The package uses `@wordpress/i18n` directly. Strings are extracted with the
@@ -10,7 +10,7 @@ const react_1 = require("react");
10
10
  const date_range_content_1 = require("./date-range-content");
11
11
  const datetime_1 = require("./datetime");
12
12
  const utils_1 = require("./utils");
13
- require("./style.scss");
13
+ require("./style.css");
14
14
  function DateRangePicker({ start, end, onChange, gmtOffset, timezoneString, locale, disableFuture = true, disabledBefore, defaultFallbackPreset = 'last-7-days', hiddenPresets, inputsProps, }) {
15
15
  const isSmall = (0, compose_1.useMediaQuery)('(max-width: 600px)');
16
16
  // Use a wider breakpoint to decide when two calendars can fit comfortably
@@ -0,0 +1,116 @@
1
+ /**
2
+ * SCSS Variables.
3
+ *
4
+ * Please use variables from this sheet to ensure consistency across the UI.
5
+ * Don't add to this sheet unless you're pretty sure the value will be reused in many places.
6
+ * For example, don't add rules to this sheet that affect block visuals. It's purely for UI.
7
+ */
8
+ /**
9
+ * Converts a hex value into the rgb equivalent.
10
+ *
11
+ * @param {string} hex - the hexadecimal value to convert
12
+ * @return {string} comma separated rgb values
13
+ */
14
+ /**
15
+ * Colors
16
+ */
17
+ /**
18
+ * Fonts & basic variables.
19
+ */
20
+ /**
21
+ * Typography
22
+ */
23
+ /**
24
+ * Grid System.
25
+ * https://make.wordpress.org/design/2019/10/31/proposal-a-consistent-spacing-system-for-wordpress/
26
+ */
27
+ /**
28
+ * Radius scale.
29
+ */
30
+ /**
31
+ * Elevation scale.
32
+ */
33
+ /**
34
+ * Dimensions.
35
+ */
36
+ /**
37
+ * Mobile specific styles
38
+ */
39
+ /**
40
+ * Editor styles.
41
+ */
42
+ /**
43
+ * Block & Editor UI.
44
+ */
45
+ /**
46
+ * Block paddings.
47
+ */
48
+ /**
49
+ * React Native specific.
50
+ * These variables do not appear to be used anywhere else.
51
+ */
52
+ /* Popover sizing */
53
+ .daterange-popover .components-popover__content {
54
+ overflow: visible;
55
+ width: auto;
56
+ max-width: calc(100vw - 48px);
57
+ }
58
+
59
+ /* Body rows */
60
+ .daterange-inputs {
61
+ margin-bottom: 12px;
62
+ }
63
+
64
+ .daterange-input__field.components-button {
65
+ background: var(--dashboard-surface__background-color, #fff);
66
+ padding: 4px 4px 4px 8px;
67
+ box-shadow: none;
68
+ border-radius: 2px;
69
+ border: 1px solid var(--dashboard-field__border-color, #949494);
70
+ }
71
+ .daterange-input__field svg {
72
+ color: var(--dashboard__text-color, #1e1e1e);
73
+ padding: 4px;
74
+ }
75
+ .daterange-input__text {
76
+ color: var(--dashboard__text-color, #1e1e1e);
77
+ padding: 0 4px;
78
+ }
79
+
80
+ /* Mobile */
81
+ @media (max-width: 600px) {
82
+ .daterange-calendar {
83
+ display: flex;
84
+ justify-content: center;
85
+ width: 100%;
86
+ }
87
+ }
88
+ /* Medium screens: presets and calendar should be centered with no awkward right margin */
89
+ @media (min-width: 601px) and (max-width: 899px) {
90
+ .daterange-body {
91
+ justify-content: space-between !important;
92
+ }
93
+ }
94
+ /* Desktop presets column: ensure a reasonable width to avoid awkward wrapping */
95
+ @media (min-width: 601px) {
96
+ .daterange-presets {
97
+ min-width: 240px;
98
+ }
99
+ }
100
+ /* Preset list items: keep buttons full-width and avoid awkward line wrapping */
101
+ .preset-listbox__item .components-button {
102
+ width: 100%;
103
+ justify-content: flex-start;
104
+ white-space: nowrap;
105
+ overflow: hidden;
106
+ text-overflow: ellipsis;
107
+ }
108
+
109
+ /* Hide native date picker icons inside our date inputs (visual only) */
110
+ .daterange-inputs input[type=date]::-webkit-calendar-picker-indicator {
111
+ display: none;
112
+ }
113
+
114
+ .daterange-inputs input[type=date]::-webkit-clear-button {
115
+ display: none;
116
+ }
@@ -7,7 +7,7 @@ import { useMemo, useState } from 'react';
7
7
  import { DateRangeContent } from './date-range-content';
8
8
  import { parseYmdLocal, formatYmd, formatSiteYmd } from './datetime';
9
9
  import { formatLabel } from './utils';
10
- import './style.scss';
10
+ import './style.css';
11
11
  export function DateRangePicker({ start, end, onChange, gmtOffset, timezoneString, locale, disableFuture = true, disabledBefore, defaultFallbackPreset = 'last-7-days', hiddenPresets, inputsProps, }) {
12
12
  const isSmall = useMediaQuery('(max-width: 600px)');
13
13
  // Use a wider breakpoint to decide when two calendars can fit comfortably
@@ -0,0 +1,116 @@
1
+ /**
2
+ * SCSS Variables.
3
+ *
4
+ * Please use variables from this sheet to ensure consistency across the UI.
5
+ * Don't add to this sheet unless you're pretty sure the value will be reused in many places.
6
+ * For example, don't add rules to this sheet that affect block visuals. It's purely for UI.
7
+ */
8
+ /**
9
+ * Converts a hex value into the rgb equivalent.
10
+ *
11
+ * @param {string} hex - the hexadecimal value to convert
12
+ * @return {string} comma separated rgb values
13
+ */
14
+ /**
15
+ * Colors
16
+ */
17
+ /**
18
+ * Fonts & basic variables.
19
+ */
20
+ /**
21
+ * Typography
22
+ */
23
+ /**
24
+ * Grid System.
25
+ * https://make.wordpress.org/design/2019/10/31/proposal-a-consistent-spacing-system-for-wordpress/
26
+ */
27
+ /**
28
+ * Radius scale.
29
+ */
30
+ /**
31
+ * Elevation scale.
32
+ */
33
+ /**
34
+ * Dimensions.
35
+ */
36
+ /**
37
+ * Mobile specific styles
38
+ */
39
+ /**
40
+ * Editor styles.
41
+ */
42
+ /**
43
+ * Block & Editor UI.
44
+ */
45
+ /**
46
+ * Block paddings.
47
+ */
48
+ /**
49
+ * React Native specific.
50
+ * These variables do not appear to be used anywhere else.
51
+ */
52
+ /* Popover sizing */
53
+ .daterange-popover .components-popover__content {
54
+ overflow: visible;
55
+ width: auto;
56
+ max-width: calc(100vw - 48px);
57
+ }
58
+
59
+ /* Body rows */
60
+ .daterange-inputs {
61
+ margin-bottom: 12px;
62
+ }
63
+
64
+ .daterange-input__field.components-button {
65
+ background: var(--dashboard-surface__background-color, #fff);
66
+ padding: 4px 4px 4px 8px;
67
+ box-shadow: none;
68
+ border-radius: 2px;
69
+ border: 1px solid var(--dashboard-field__border-color, #949494);
70
+ }
71
+ .daterange-input__field svg {
72
+ color: var(--dashboard__text-color, #1e1e1e);
73
+ padding: 4px;
74
+ }
75
+ .daterange-input__text {
76
+ color: var(--dashboard__text-color, #1e1e1e);
77
+ padding: 0 4px;
78
+ }
79
+
80
+ /* Mobile */
81
+ @media (max-width: 600px) {
82
+ .daterange-calendar {
83
+ display: flex;
84
+ justify-content: center;
85
+ width: 100%;
86
+ }
87
+ }
88
+ /* Medium screens: presets and calendar should be centered with no awkward right margin */
89
+ @media (min-width: 601px) and (max-width: 899px) {
90
+ .daterange-body {
91
+ justify-content: space-between !important;
92
+ }
93
+ }
94
+ /* Desktop presets column: ensure a reasonable width to avoid awkward wrapping */
95
+ @media (min-width: 601px) {
96
+ .daterange-presets {
97
+ min-width: 240px;
98
+ }
99
+ }
100
+ /* Preset list items: keep buttons full-width and avoid awkward line wrapping */
101
+ .preset-listbox__item .components-button {
102
+ width: 100%;
103
+ justify-content: flex-start;
104
+ white-space: nowrap;
105
+ overflow: hidden;
106
+ text-overflow: ellipsis;
107
+ }
108
+
109
+ /* Hide native date picker icons inside our date inputs (visual only) */
110
+ .daterange-inputs input[type=date]::-webkit-calendar-picker-indicator {
111
+ display: none;
112
+ }
113
+
114
+ .daterange-inputs input[type=date]::-webkit-clear-button {
115
+ display: none;
116
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/date-range-picker",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A date-range picker built on top of @automattic/ui's DateRangeCalendar, with timezone-aware site-day handling, preset shortcuts, and accessible inputs.",
5
5
  "homepage": "https://github.com/Automattic/wp-calypso",
6
6
  "license": "GPL-2.0-or-later",
@@ -20,8 +20,7 @@
20
20
  }
21
21
  },
22
22
  "sideEffects": [
23
- "*.css",
24
- "*.scss"
23
+ "*.css"
25
24
  ],
26
25
  "repository": {
27
26
  "type": "git",
@@ -34,29 +33,52 @@
34
33
  "bugs": "https://github.com/Automattic/wp-calypso/issues",
35
34
  "files": [
36
35
  "dist",
37
- "src"
36
+ "src",
37
+ "!dist/**/*.tsbuildinfo",
38
+ "!src/test"
38
39
  ],
39
40
  "types": "dist/types",
40
41
  "scripts": {
41
42
  "clean": "tsc --build ./tsconfig.json ./tsconfig-cjs.json --clean && rm -rf dist",
42
- "build": "tsc --build ./tsconfig.json ./tsconfig-cjs.json",
43
+ "build": "tsc --build ./tsconfig.json ./tsconfig-cjs.json && node ./bin/build-styles.js",
43
44
  "prepack": "yarn run clean && yarn run build"
44
45
  },
45
46
  "dependencies": {
46
47
  "@automattic/ui": "^1.0.2",
47
- "@wordpress/base-styles": "^5.23.0",
48
- "@wordpress/components": "^32.1.0",
49
- "@wordpress/compose": "7.23.0",
50
- "@wordpress/date": "5.23.0",
51
- "@wordpress/i18n": "^5.23.0",
52
- "@wordpress/icons": "^10.23.0",
53
- "date-fns": "^4.1.0",
54
- "tslib": "^2.8.1"
48
+ "date-fns": "^4.1.0"
55
49
  },
56
50
  "peerDependencies": {
51
+ "@wordpress/components": ">=32.1.0",
52
+ "@wordpress/compose": ">=7.23.0",
53
+ "@wordpress/date": ">=5.23.0",
54
+ "@wordpress/i18n": ">=5.23.0",
55
+ "@wordpress/icons": ">=10.23.0",
57
56
  "react": "^18.3.1",
58
57
  "react-dom": "^18.3.1"
59
58
  },
59
+ "peerDependenciesMeta": {
60
+ "@wordpress/components": {
61
+ "optional": false
62
+ },
63
+ "@wordpress/compose": {
64
+ "optional": false
65
+ },
66
+ "@wordpress/date": {
67
+ "optional": false
68
+ },
69
+ "@wordpress/i18n": {
70
+ "optional": false
71
+ },
72
+ "@wordpress/icons": {
73
+ "optional": false
74
+ },
75
+ "react": {
76
+ "optional": false
77
+ },
78
+ "react-dom": {
79
+ "optional": false
80
+ }
81
+ },
60
82
  "devDependencies": {
61
83
  "@automattic/calypso-typescript-config": "^1.0.0",
62
84
  "@testing-library/dom": "^10.4.1",
@@ -64,8 +86,17 @@
64
86
  "@testing-library/react": "^16.3.0",
65
87
  "@testing-library/user-event": "^14.6.1",
66
88
  "@types/react": "^18.3.18",
89
+ "@wordpress/base-styles": "^5.23.0",
90
+ "@wordpress/components": "^32.1.0",
91
+ "@wordpress/compose": "7.23.0",
92
+ "@wordpress/date": "5.23.0",
93
+ "@wordpress/i18n": "^5.23.0",
94
+ "@wordpress/icons": "^10.23.0",
67
95
  "jest": "^29.7.0",
68
96
  "mockdate": "^2.0.5",
69
- "typescript": "^5.8.3"
97
+ "postcss": "^8.5.3",
98
+ "sass": "1.77.8",
99
+ "typescript": "^5.8.3",
100
+ "webpack": "^5.99.8"
70
101
  }
71
102
  }
package/src/style.scss CHANGED
@@ -1,3 +1,5 @@
1
+ @use "@wordpress/base-styles/variables" as v;
2
+
1
3
  /* Popover sizing */
2
4
  .daterange-popover .components-popover__content {
3
5
  overflow: visible;
@@ -14,20 +16,20 @@
14
16
  &__field {
15
17
  // The extra class is to make sure it overrides the default button styles
16
18
  &.components-button {
17
- background: var( --dashboard-surface__background-color );
18
- padding: $grid-unit-05 $grid-unit-05 $grid-unit-05 $grid-unit-10;
19
+ background: var(--dashboard-surface__background-color, #fff);
20
+ padding: v.$grid-unit-05 v.$grid-unit-05 v.$grid-unit-05 v.$grid-unit-10;
19
21
  box-shadow: none;
20
- border-radius: $radius-small;
21
- border: 1px solid var(--dashboard-field__border-color, $gray-600);
22
+ border-radius: v.$radius-small;
23
+ border: 1px solid var(--dashboard-field__border-color, #{v.$gray-600});
22
24
  }
23
25
  svg {
24
- color: var(--dashboard__text-color);
25
- padding: $grid-unit-05;
26
+ color: var(--dashboard__text-color, #{v.$gray-900});
27
+ padding: v.$grid-unit-05;
26
28
  }
27
29
  }
28
30
  &__text {
29
- color: var(--dashboard__text-color);
30
- padding: 0 $grid-unit-05;
31
+ color: var(--dashboard__text-color, #{v.$gray-900});
32
+ padding: 0 v.$grid-unit-05;
31
33
  }
32
34
  }
33
35
 
package/src/types.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  declare module '*.scss';
2
+ declare module '*.css';