@atlaskit/primitives 0.2.2 → 0.3.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/primitives
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`7c280fead96`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7c280fead96) - Add new responsive helpers, breakpoints config, and types into `@atlaskit/primitives/responsive`. Exports are treated as `UNSAFE_` and experimental until modified as they're being worked on in parallel to our Alpha Grid.
8
+
3
9
  ## 0.2.2
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.UNSAFE_buildBelowMediaQueryCSS = exports.UNSAFE_buildAboveMediaQueryCSS = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _react = require("@emotion/react");
11
+ var _constants = require("./constants");
12
+ var _mediaHelper = require("./media-helper");
13
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
14
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
+ /**
16
+ * Build a map of breakpoints to css with media queries and nested styles.
17
+ *
18
+ * @experimental Unsafe for usage as the API is not finalized.
19
+ *
20
+ * @example
21
+ * A map to build optional `display:none` for consumption on a div.
22
+ * ```ts
23
+ * const hideMediaQueries = buildAboveMediaQueryCSS({ display: 'none' });
24
+ *
25
+ * const Component = ({ hideAtBreakpoints: ('xs' | 'sm')[], children: ReactNode }) => {
26
+ * return <div css={hideAtBreakpoints.map(b => hideMediaQueries[b])}>{children}</div>;
27
+ * }
28
+ * ```
29
+ *
30
+ * This roughly builds a map that will look roughly like this (if done manually):
31
+ * ```ts
32
+ * {
33
+ * xxs: css({ '@media (min-width: 0px)': { display: 'none' } }),
34
+ * xs: css({ '@media (min-width: …px)': { display: 'none' } }),
35
+ * sm: css({ '@media (min-width: …px)': { display: 'none' } }),
36
+ * }
37
+ * ```
38
+ */
39
+ var UNSAFE_buildAboveMediaQueryCSS = function UNSAFE_buildAboveMediaQueryCSS(input) {
40
+ return _constants.UNSAFE_BREAKPOINTS_ORDERED_LIST.reduce(function (acc, breakpoint) {
41
+ return _objectSpread(_objectSpread({}, acc), {}, (0, _defineProperty2.default)({}, breakpoint, (0, _react.css)((0, _defineProperty2.default)({}, _mediaHelper.UNSAFE_media.above[breakpoint], typeof input === 'function' ? input(breakpoint) : input))));
42
+ }, {});
43
+ };
44
+
45
+ /**
46
+ * Build a map of breakpoints to css with media queries and nested styles.
47
+ *
48
+ * WARNING: The smallest breakpoint is not a valid key as a media query below 0px is misleading.
49
+ * This is separated from `buildAboveMediaQueryCSS` for that specific reason, you cannot have type safety with this variance.
50
+ *
51
+ * @experimental Unsafe for usage as the API is not finalized.
52
+ *
53
+ * @example
54
+ * A map to build optional `display:none` for consumption on a div.
55
+ * ```ts
56
+ * const hideMediaQueries = buildBelowMediaQueryCSS({ display: 'none' });
57
+ *
58
+ * const Component = ({ hideAtBreakpoints: ('xs' | 'sm')[], children: ReactNode }) => {
59
+ * return <div css={hideAtBreakpoints.map(b => hideMediaQueries[b])}>{children}</div>;
60
+ * }
61
+ * ```
62
+ *
63
+ * This roughly builds a map that will look roughly like this (if done manually):
64
+ * ```ts
65
+ * {
66
+ * xs: css({ '@media (max-width: …px)': { display: 'none' } }),
67
+ * sm: css({ '@media (max-width: …px)': { display: 'none' } }),
68
+ * }
69
+ * ```
70
+ *
71
+ * @experimental Unsafe for usage as the API is not finalized.
72
+ */
73
+ exports.UNSAFE_buildAboveMediaQueryCSS = UNSAFE_buildAboveMediaQueryCSS;
74
+ var UNSAFE_buildBelowMediaQueryCSS = function UNSAFE_buildBelowMediaQueryCSS(input) {
75
+ /**
76
+ * WARNING: it's very important that these are in the correct order.
77
+ * If they are not, cascading is not in the order higher/low breakpoints do not override as expected.
78
+ */
79
+ var reversedBreakpoints = (0, _toConsumableArray2.default)(_constants.UNSAFE_BREAKPOINTS_ORDERED_LIST).reverse();
80
+ return reversedBreakpoints.reduce(function (acc, breakpoint) {
81
+ // Omit `media.below.xxs` as it's not available as that would be `<0px`…
82
+ if (breakpoint === _constants.SMALLEST_BREAKPOINT) {
83
+ return acc;
84
+ }
85
+ return _objectSpread(_objectSpread({}, acc), {}, (0, _defineProperty2.default)({}, breakpoint, (0, _react.css)((0, _defineProperty2.default)({}, _mediaHelper.UNSAFE_media.below[breakpoint], typeof input === 'function' ? input(breakpoint) : input))));
86
+ }, {});
87
+ };
88
+ exports.UNSAFE_buildBelowMediaQueryCSS = UNSAFE_buildBelowMediaQueryCSS;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.UNSAFE_BREAKPOINTS_ORDERED_LIST = exports.UNSAFE_BREAKPOINTS_CONFIG = exports.SMALLEST_BREAKPOINT = void 0;
7
+ /**
8
+ * Our internal configuration for breakpoints configuration.
9
+ *
10
+ * @experimental Unsafe for consumption outside of the design system itself.
11
+ */
12
+ var UNSAFE_BREAKPOINTS_CONFIG = {
13
+ // mobile
14
+ xxs: {
15
+ gridItemGutter: "var(--ds-space-200, 16px)",
16
+ gridMargin: "var(--ds-space-200, 16px)",
17
+ min: 0,
18
+ max: 479
19
+ },
20
+ // phablet
21
+ xs: {
22
+ gridItemGutter: "var(--ds-space-200, 16px)",
23
+ gridMargin: "var(--ds-space-200, 16px)",
24
+ min: 480,
25
+ max: 767
26
+ },
27
+ // tablet
28
+ sm: {
29
+ gridItemGutter: "var(--ds-space-200, 16px)",
30
+ gridMargin: "var(--ds-space-300, 24px)",
31
+ min: 768,
32
+ max: 1023
33
+ },
34
+ // laptop desktop
35
+ md: {
36
+ gridItemGutter: "var(--ds-space-300, 24px)",
37
+ gridMargin: "var(--ds-space-400, 32px)",
38
+ min: 1024,
39
+ max: 1439
40
+ },
41
+ // monitor
42
+ lg: {
43
+ gridItemGutter: "var(--ds-space-400, 32px)",
44
+ gridMargin: "var(--ds-space-400, 32px)",
45
+ min: 1440,
46
+ max: 1767
47
+ },
48
+ // large high res
49
+ xl: {
50
+ gridItemGutter: "var(--ds-space-400, 32px)",
51
+ gridMargin: "var(--ds-space-500, 40px)",
52
+ min: 1768,
53
+ max: 2159
54
+ },
55
+ // extra large high res
56
+ xxl: {
57
+ gridItemGutter: "var(--ds-space-500, 40px)",
58
+ gridMargin: "var(--ds-space-500, 40px)",
59
+ min: 2160,
60
+ max: Number.MAX_SAFE_INTEGER
61
+ }
62
+ };
63
+
64
+ /**
65
+ * The list of breakpoints in order from smallest to largest. You may need to clone and reverse this list if you want the opposite.
66
+ *
67
+ * This is intentional for cascading with `min-width` or `media.above`. Media queries go from lowest width to highest.
68
+ *
69
+ * @experimental Unsafe for consumption outside of the design system itself.
70
+ */
71
+ exports.UNSAFE_BREAKPOINTS_CONFIG = UNSAFE_BREAKPOINTS_CONFIG;
72
+ var UNSAFE_BREAKPOINTS_ORDERED_LIST = Object.keys(UNSAFE_BREAKPOINTS_CONFIG).sort(function (a, b) {
73
+ return UNSAFE_BREAKPOINTS_CONFIG[a].min - UNSAFE_BREAKPOINTS_CONFIG[b].min;
74
+ });
75
+
76
+ /**
77
+ * This is our smallest breakpoint with a few nuances to it:
78
+ * 1. It is the default value for shorthands, eg. `<GridItem span={6} />` maps to `{ [SMALLEST_BREAKPOINT]: props.span }`
79
+ * 2. It's omitted in `media.below` as there's nothing below `0px`.
80
+ *
81
+ * @experimental There's a chance this will change in _value_, but should only be used in a way that it will not matter if this value changes.
82
+ */
83
+ exports.UNSAFE_BREAKPOINTS_ORDERED_LIST = UNSAFE_BREAKPOINTS_ORDERED_LIST;
84
+ var SMALLEST_BREAKPOINT = UNSAFE_BREAKPOINTS_ORDERED_LIST[0];
85
+ exports.SMALLEST_BREAKPOINT = SMALLEST_BREAKPOINT;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "UNSAFE_BREAKPOINTS_CONFIG", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _constants.UNSAFE_BREAKPOINTS_CONFIG;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "UNSAFE_BREAKPOINTS_ORDERED_LIST", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _constants.UNSAFE_BREAKPOINTS_ORDERED_LIST;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "UNSAFE_buildAboveMediaQueryCSS", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _buildMediaQueryCss.UNSAFE_buildAboveMediaQueryCSS;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "UNSAFE_buildBelowMediaQueryCSS", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _buildMediaQueryCss.UNSAFE_buildBelowMediaQueryCSS;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "UNSAFE_media", {
31
+ enumerable: true,
32
+ get: function get() {
33
+ return _mediaHelper.UNSAFE_media;
34
+ }
35
+ });
36
+ var _mediaHelper = require("./media-helper");
37
+ var _buildMediaQueryCss = require("./build-media-query-css");
38
+ var _constants = require("./constants");
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.UNSAFE_media = void 0;
7
+ var _constants = require("./constants");
8
+ /**
9
+ * To ensure min-width and max-width do both target at the same time, we subtract a value.
10
+ * We use a fractional value here as used in other libraries and described in @link https://www.w3.org/TR/mediaqueries-4/#mq-min-max: "…possibility of fractional viewport sizes which can occur as a result of non-integer pixel densities…"
11
+ */
12
+ var BELOW_PRECISION = 0.02;
13
+
14
+ /**
15
+ * This is the full internal version. The import has been separated to only expose as-needed.
16
+ */
17
+ var internalMedia = {
18
+ /**
19
+ * A media query to target viewports above the min width of a given breakpoint.
20
+ * Note that `media.above.xs` is redundant and should not be used, but it's included for programatic purposes.
21
+ */
22
+ above: {
23
+ /**
24
+ * `above.xxs` is redundant and no media query should be used, but it's included for programatic purposes…
25
+ *
26
+ * Eg. this is `@media (min-width: 0px)`
27
+ */
28
+ xxs: "@media (min-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.xxs.min, "px)"),
29
+ xs: "@media (min-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.xs.min, "px)"),
30
+ sm: "@media (min-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.sm.min, "px)"),
31
+ md: "@media (min-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.md.min, "px)"),
32
+ lg: "@media (min-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.lg.min, "px)"),
33
+ xl: "@media (min-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.xl.min, "px)"),
34
+ xxl: "@media (min-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.xxl.min, "px)")
35
+ },
36
+ below: {
37
+ /**
38
+ * A media query to target viewports below the min width of a given breakpoint.
39
+ * Note that `media.below.xxs` is intentionally omitted as this would be `@media (max-width: 0px)`
40
+ */
41
+ xs: "@media (max-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.xs.min - BELOW_PRECISION, "px)"),
42
+ sm: "@media (max-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.sm.min - BELOW_PRECISION, "px)"),
43
+ md: "@media (max-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.md.min - BELOW_PRECISION, "px)"),
44
+ lg: "@media (max-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.lg.min - BELOW_PRECISION, "px)"),
45
+ xl: "@media (max-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.xl.min - BELOW_PRECISION, "px)"),
46
+ xxl: "@media (max-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.xxl.min - BELOW_PRECISION, "px)")
47
+ },
48
+ /**
49
+ * A media query to target viewports exactly between the min and max of a given breakpoint.
50
+ */
51
+ only: {
52
+ xxs: "@media (min-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.xxs.min, "px) and (max-width: ").concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.xxs.max, "px)"),
53
+ xs: "@media (min-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.xs.min, "px) and (max-width: ").concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.xs.max, "px)"),
54
+ sm: "@media (min-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.sm.min, "px) and (max-width: ").concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.sm.max, "px)"),
55
+ md: "@media (min-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.md.min, "px) and (max-width: ").concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.md.max, "px)"),
56
+ lg: "@media (min-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.lg.min, "px) and (max-width: ").concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.lg.max, "px)"),
57
+ xl: "@media (min-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.xl.min, "px) and (max-width: ").concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.xl.max, "px)"),
58
+ xxl: "@media (min-width: ".concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.xxl.min, "px) and (max-width: ").concat(_constants.UNSAFE_BREAKPOINTS_CONFIG.xxl.max, "px)")
59
+ }
60
+ };
61
+
62
+ /**
63
+ * This is an object of usable media query helpers using our internal breakpoints configuration.
64
+ *
65
+ * @experimental Unsafe for usage as the API is not finalized.
66
+ */
67
+ var UNSAFE_media = {
68
+ above: internalMedia.above,
69
+ below: internalMedia.below
70
+ };
71
+
72
+ /**
73
+ * With these types:
74
+ * ```
75
+ * type MediaQuery = `@media (${string})`;
76
+ * type ResponsiveMediaObject = Record<Breakpoint, MediaQuery>;
77
+ * ```
78
+ *
79
+ * TODO: This `media` object as of typescript@4.9, would benefit from satisfies, eg.:
80
+ * ```
81
+ * const UNSAFE_media = { … } satisfies Record<'above' | 'only', ResponsiveMediaObject> & { below: Omit<ResponsiveMediaObject, 'xxs'> }
82
+ * ```
83
+ */
84
+ exports.UNSAFE_media = UNSAFE_media;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/primitives",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,85 @@
1
+ import { css } from '@emotion/react';
2
+ import { SMALLEST_BREAKPOINT, UNSAFE_BREAKPOINTS_ORDERED_LIST } from './constants';
3
+ import { UNSAFE_media } from './media-helper';
4
+ /**
5
+ * Build a map of breakpoints to css with media queries and nested styles.
6
+ *
7
+ * @experimental Unsafe for usage as the API is not finalized.
8
+ *
9
+ * @example
10
+ * A map to build optional `display:none` for consumption on a div.
11
+ * ```ts
12
+ * const hideMediaQueries = buildAboveMediaQueryCSS({ display: 'none' });
13
+ *
14
+ * const Component = ({ hideAtBreakpoints: ('xs' | 'sm')[], children: ReactNode }) => {
15
+ * return <div css={hideAtBreakpoints.map(b => hideMediaQueries[b])}>{children}</div>;
16
+ * }
17
+ * ```
18
+ *
19
+ * This roughly builds a map that will look roughly like this (if done manually):
20
+ * ```ts
21
+ * {
22
+ * xxs: css({ '@media (min-width: 0px)': { display: 'none' } }),
23
+ * xs: css({ '@media (min-width: …px)': { display: 'none' } }),
24
+ * sm: css({ '@media (min-width: …px)': { display: 'none' } }),
25
+ * }
26
+ * ```
27
+ */
28
+ export const UNSAFE_buildAboveMediaQueryCSS = input => {
29
+ return UNSAFE_BREAKPOINTS_ORDERED_LIST.reduce((acc, breakpoint) => ({
30
+ ...acc,
31
+ [breakpoint]: css({
32
+ // eslint-disable-next-line @repo/internal/styles/no-nested-styles
33
+ [UNSAFE_media.above[breakpoint]]: typeof input === 'function' ? input(breakpoint) : input
34
+ })
35
+ }), {});
36
+ };
37
+
38
+ /**
39
+ * Build a map of breakpoints to css with media queries and nested styles.
40
+ *
41
+ * WARNING: The smallest breakpoint is not a valid key as a media query below 0px is misleading.
42
+ * This is separated from `buildAboveMediaQueryCSS` for that specific reason, you cannot have type safety with this variance.
43
+ *
44
+ * @experimental Unsafe for usage as the API is not finalized.
45
+ *
46
+ * @example
47
+ * A map to build optional `display:none` for consumption on a div.
48
+ * ```ts
49
+ * const hideMediaQueries = buildBelowMediaQueryCSS({ display: 'none' });
50
+ *
51
+ * const Component = ({ hideAtBreakpoints: ('xs' | 'sm')[], children: ReactNode }) => {
52
+ * return <div css={hideAtBreakpoints.map(b => hideMediaQueries[b])}>{children}</div>;
53
+ * }
54
+ * ```
55
+ *
56
+ * This roughly builds a map that will look roughly like this (if done manually):
57
+ * ```ts
58
+ * {
59
+ * xs: css({ '@media (max-width: …px)': { display: 'none' } }),
60
+ * sm: css({ '@media (max-width: …px)': { display: 'none' } }),
61
+ * }
62
+ * ```
63
+ *
64
+ * @experimental Unsafe for usage as the API is not finalized.
65
+ */
66
+ export const UNSAFE_buildBelowMediaQueryCSS = input => {
67
+ /**
68
+ * WARNING: it's very important that these are in the correct order.
69
+ * If they are not, cascading is not in the order higher/low breakpoints do not override as expected.
70
+ */
71
+ const reversedBreakpoints = [...UNSAFE_BREAKPOINTS_ORDERED_LIST].reverse();
72
+ return reversedBreakpoints.reduce((acc, breakpoint) => {
73
+ // Omit `media.below.xxs` as it's not available as that would be `<0px`…
74
+ if (breakpoint === SMALLEST_BREAKPOINT) {
75
+ return acc;
76
+ }
77
+ return {
78
+ ...acc,
79
+ [breakpoint]: css({
80
+ // eslint-disable-next-line @repo/internal/styles/no-nested-styles
81
+ [UNSAFE_media.below[breakpoint]]: typeof input === 'function' ? input(breakpoint) : input
82
+ })
83
+ };
84
+ }, {});
85
+ };
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Our internal configuration for breakpoints configuration.
3
+ *
4
+ * @experimental Unsafe for consumption outside of the design system itself.
5
+ */
6
+ export const UNSAFE_BREAKPOINTS_CONFIG = {
7
+ // mobile
8
+ xxs: {
9
+ gridItemGutter: "var(--ds-space-200, 16px)",
10
+ gridMargin: "var(--ds-space-200, 16px)",
11
+ min: 0,
12
+ max: 479
13
+ },
14
+ // phablet
15
+ xs: {
16
+ gridItemGutter: "var(--ds-space-200, 16px)",
17
+ gridMargin: "var(--ds-space-200, 16px)",
18
+ min: 480,
19
+ max: 767
20
+ },
21
+ // tablet
22
+ sm: {
23
+ gridItemGutter: "var(--ds-space-200, 16px)",
24
+ gridMargin: "var(--ds-space-300, 24px)",
25
+ min: 768,
26
+ max: 1023
27
+ },
28
+ // laptop desktop
29
+ md: {
30
+ gridItemGutter: "var(--ds-space-300, 24px)",
31
+ gridMargin: "var(--ds-space-400, 32px)",
32
+ min: 1024,
33
+ max: 1439
34
+ },
35
+ // monitor
36
+ lg: {
37
+ gridItemGutter: "var(--ds-space-400, 32px)",
38
+ gridMargin: "var(--ds-space-400, 32px)",
39
+ min: 1440,
40
+ max: 1767
41
+ },
42
+ // large high res
43
+ xl: {
44
+ gridItemGutter: "var(--ds-space-400, 32px)",
45
+ gridMargin: "var(--ds-space-500, 40px)",
46
+ min: 1768,
47
+ max: 2159
48
+ },
49
+ // extra large high res
50
+ xxl: {
51
+ gridItemGutter: "var(--ds-space-500, 40px)",
52
+ gridMargin: "var(--ds-space-500, 40px)",
53
+ min: 2160,
54
+ max: Number.MAX_SAFE_INTEGER
55
+ }
56
+ };
57
+
58
+ /**
59
+ * The list of breakpoints in order from smallest to largest. You may need to clone and reverse this list if you want the opposite.
60
+ *
61
+ * This is intentional for cascading with `min-width` or `media.above`. Media queries go from lowest width to highest.
62
+ *
63
+ * @experimental Unsafe for consumption outside of the design system itself.
64
+ */
65
+ export const UNSAFE_BREAKPOINTS_ORDERED_LIST = Object.keys(UNSAFE_BREAKPOINTS_CONFIG).sort((a, b) => UNSAFE_BREAKPOINTS_CONFIG[a].min - UNSAFE_BREAKPOINTS_CONFIG[b].min);
66
+
67
+ /**
68
+ * This is our smallest breakpoint with a few nuances to it:
69
+ * 1. It is the default value for shorthands, eg. `<GridItem span={6} />` maps to `{ [SMALLEST_BREAKPOINT]: props.span }`
70
+ * 2. It's omitted in `media.below` as there's nothing below `0px`.
71
+ *
72
+ * @experimental There's a chance this will change in _value_, but should only be used in a way that it will not matter if this value changes.
73
+ */
74
+ export const SMALLEST_BREAKPOINT = UNSAFE_BREAKPOINTS_ORDERED_LIST[0];
@@ -0,0 +1,3 @@
1
+ export { UNSAFE_media } from './media-helper';
2
+ export { UNSAFE_buildAboveMediaQueryCSS, UNSAFE_buildBelowMediaQueryCSS } from './build-media-query-css';
3
+ export { UNSAFE_BREAKPOINTS_ORDERED_LIST, UNSAFE_BREAKPOINTS_CONFIG } from './constants';
@@ -0,0 +1,78 @@
1
+ import { UNSAFE_BREAKPOINTS_CONFIG } from './constants';
2
+
3
+ /**
4
+ * To ensure min-width and max-width do both target at the same time, we subtract a value.
5
+ * We use a fractional value here as used in other libraries and described in @link https://www.w3.org/TR/mediaqueries-4/#mq-min-max: "…possibility of fractional viewport sizes which can occur as a result of non-integer pixel densities…"
6
+ */
7
+ const BELOW_PRECISION = 0.02;
8
+
9
+ /**
10
+ * This is the full internal version. The import has been separated to only expose as-needed.
11
+ */
12
+ const internalMedia = {
13
+ /**
14
+ * A media query to target viewports above the min width of a given breakpoint.
15
+ * Note that `media.above.xs` is redundant and should not be used, but it's included for programatic purposes.
16
+ */
17
+ above: {
18
+ /**
19
+ * `above.xxs` is redundant and no media query should be used, but it's included for programatic purposes…
20
+ *
21
+ * Eg. this is `@media (min-width: 0px)`
22
+ */
23
+ xxs: `@media (min-width: ${UNSAFE_BREAKPOINTS_CONFIG.xxs.min}px)`,
24
+ xs: `@media (min-width: ${UNSAFE_BREAKPOINTS_CONFIG.xs.min}px)`,
25
+ sm: `@media (min-width: ${UNSAFE_BREAKPOINTS_CONFIG.sm.min}px)`,
26
+ md: `@media (min-width: ${UNSAFE_BREAKPOINTS_CONFIG.md.min}px)`,
27
+ lg: `@media (min-width: ${UNSAFE_BREAKPOINTS_CONFIG.lg.min}px)`,
28
+ xl: `@media (min-width: ${UNSAFE_BREAKPOINTS_CONFIG.xl.min}px)`,
29
+ xxl: `@media (min-width: ${UNSAFE_BREAKPOINTS_CONFIG.xxl.min}px)`
30
+ },
31
+ below: {
32
+ /**
33
+ * A media query to target viewports below the min width of a given breakpoint.
34
+ * Note that `media.below.xxs` is intentionally omitted as this would be `@media (max-width: 0px)`
35
+ */
36
+ xs: `@media (max-width: ${UNSAFE_BREAKPOINTS_CONFIG.xs.min - BELOW_PRECISION}px)`,
37
+ sm: `@media (max-width: ${UNSAFE_BREAKPOINTS_CONFIG.sm.min - BELOW_PRECISION}px)`,
38
+ md: `@media (max-width: ${UNSAFE_BREAKPOINTS_CONFIG.md.min - BELOW_PRECISION}px)`,
39
+ lg: `@media (max-width: ${UNSAFE_BREAKPOINTS_CONFIG.lg.min - BELOW_PRECISION}px)`,
40
+ xl: `@media (max-width: ${UNSAFE_BREAKPOINTS_CONFIG.xl.min - BELOW_PRECISION}px)`,
41
+ xxl: `@media (max-width: ${UNSAFE_BREAKPOINTS_CONFIG.xxl.min - BELOW_PRECISION}px)`
42
+ },
43
+ /**
44
+ * A media query to target viewports exactly between the min and max of a given breakpoint.
45
+ */
46
+ only: {
47
+ xxs: `@media (min-width: ${UNSAFE_BREAKPOINTS_CONFIG.xxs.min}px) and (max-width: ${UNSAFE_BREAKPOINTS_CONFIG.xxs.max}px)`,
48
+ xs: `@media (min-width: ${UNSAFE_BREAKPOINTS_CONFIG.xs.min}px) and (max-width: ${UNSAFE_BREAKPOINTS_CONFIG.xs.max}px)`,
49
+ sm: `@media (min-width: ${UNSAFE_BREAKPOINTS_CONFIG.sm.min}px) and (max-width: ${UNSAFE_BREAKPOINTS_CONFIG.sm.max}px)`,
50
+ md: `@media (min-width: ${UNSAFE_BREAKPOINTS_CONFIG.md.min}px) and (max-width: ${UNSAFE_BREAKPOINTS_CONFIG.md.max}px)`,
51
+ lg: `@media (min-width: ${UNSAFE_BREAKPOINTS_CONFIG.lg.min}px) and (max-width: ${UNSAFE_BREAKPOINTS_CONFIG.lg.max}px)`,
52
+ xl: `@media (min-width: ${UNSAFE_BREAKPOINTS_CONFIG.xl.min}px) and (max-width: ${UNSAFE_BREAKPOINTS_CONFIG.xl.max}px)`,
53
+ xxl: `@media (min-width: ${UNSAFE_BREAKPOINTS_CONFIG.xxl.min}px) and (max-width: ${UNSAFE_BREAKPOINTS_CONFIG.xxl.max}px)`
54
+ }
55
+ };
56
+
57
+ /**
58
+ * This is an object of usable media query helpers using our internal breakpoints configuration.
59
+ *
60
+ * @experimental Unsafe for usage as the API is not finalized.
61
+ */
62
+ export const UNSAFE_media = {
63
+ above: internalMedia.above,
64
+ below: internalMedia.below
65
+ };
66
+
67
+ /**
68
+ * With these types:
69
+ * ```
70
+ * type MediaQuery = `@media (${string})`;
71
+ * type ResponsiveMediaObject = Record<Breakpoint, MediaQuery>;
72
+ * ```
73
+ *
74
+ * TODO: This `media` object as of typescript@4.9, would benefit from satisfies, eg.:
75
+ * ```
76
+ * const UNSAFE_media = { … } satisfies Record<'above' | 'only', ResponsiveMediaObject> & { below: Omit<ResponsiveMediaObject, 'xxs'> }
77
+ * ```
78
+ */
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/primitives",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,79 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
5
+ import { css } from '@emotion/react';
6
+ import { SMALLEST_BREAKPOINT, UNSAFE_BREAKPOINTS_ORDERED_LIST } from './constants';
7
+ import { UNSAFE_media } from './media-helper';
8
+ /**
9
+ * Build a map of breakpoints to css with media queries and nested styles.
10
+ *
11
+ * @experimental Unsafe for usage as the API is not finalized.
12
+ *
13
+ * @example
14
+ * A map to build optional `display:none` for consumption on a div.
15
+ * ```ts
16
+ * const hideMediaQueries = buildAboveMediaQueryCSS({ display: 'none' });
17
+ *
18
+ * const Component = ({ hideAtBreakpoints: ('xs' | 'sm')[], children: ReactNode }) => {
19
+ * return <div css={hideAtBreakpoints.map(b => hideMediaQueries[b])}>{children}</div>;
20
+ * }
21
+ * ```
22
+ *
23
+ * This roughly builds a map that will look roughly like this (if done manually):
24
+ * ```ts
25
+ * {
26
+ * xxs: css({ '@media (min-width: 0px)': { display: 'none' } }),
27
+ * xs: css({ '@media (min-width: …px)': { display: 'none' } }),
28
+ * sm: css({ '@media (min-width: …px)': { display: 'none' } }),
29
+ * }
30
+ * ```
31
+ */
32
+ export var UNSAFE_buildAboveMediaQueryCSS = function UNSAFE_buildAboveMediaQueryCSS(input) {
33
+ return UNSAFE_BREAKPOINTS_ORDERED_LIST.reduce(function (acc, breakpoint) {
34
+ return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, breakpoint, css(_defineProperty({}, UNSAFE_media.above[breakpoint], typeof input === 'function' ? input(breakpoint) : input))));
35
+ }, {});
36
+ };
37
+
38
+ /**
39
+ * Build a map of breakpoints to css with media queries and nested styles.
40
+ *
41
+ * WARNING: The smallest breakpoint is not a valid key as a media query below 0px is misleading.
42
+ * This is separated from `buildAboveMediaQueryCSS` for that specific reason, you cannot have type safety with this variance.
43
+ *
44
+ * @experimental Unsafe for usage as the API is not finalized.
45
+ *
46
+ * @example
47
+ * A map to build optional `display:none` for consumption on a div.
48
+ * ```ts
49
+ * const hideMediaQueries = buildBelowMediaQueryCSS({ display: 'none' });
50
+ *
51
+ * const Component = ({ hideAtBreakpoints: ('xs' | 'sm')[], children: ReactNode }) => {
52
+ * return <div css={hideAtBreakpoints.map(b => hideMediaQueries[b])}>{children}</div>;
53
+ * }
54
+ * ```
55
+ *
56
+ * This roughly builds a map that will look roughly like this (if done manually):
57
+ * ```ts
58
+ * {
59
+ * xs: css({ '@media (max-width: …px)': { display: 'none' } }),
60
+ * sm: css({ '@media (max-width: …px)': { display: 'none' } }),
61
+ * }
62
+ * ```
63
+ *
64
+ * @experimental Unsafe for usage as the API is not finalized.
65
+ */
66
+ export var UNSAFE_buildBelowMediaQueryCSS = function UNSAFE_buildBelowMediaQueryCSS(input) {
67
+ /**
68
+ * WARNING: it's very important that these are in the correct order.
69
+ * If they are not, cascading is not in the order higher/low breakpoints do not override as expected.
70
+ */
71
+ var reversedBreakpoints = _toConsumableArray(UNSAFE_BREAKPOINTS_ORDERED_LIST).reverse();
72
+ return reversedBreakpoints.reduce(function (acc, breakpoint) {
73
+ // Omit `media.below.xxs` as it's not available as that would be `<0px`…
74
+ if (breakpoint === SMALLEST_BREAKPOINT) {
75
+ return acc;
76
+ }
77
+ return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, breakpoint, css(_defineProperty({}, UNSAFE_media.below[breakpoint], typeof input === 'function' ? input(breakpoint) : input))));
78
+ }, {});
79
+ };
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Our internal configuration for breakpoints configuration.
3
+ *
4
+ * @experimental Unsafe for consumption outside of the design system itself.
5
+ */
6
+ export var UNSAFE_BREAKPOINTS_CONFIG = {
7
+ // mobile
8
+ xxs: {
9
+ gridItemGutter: "var(--ds-space-200, 16px)",
10
+ gridMargin: "var(--ds-space-200, 16px)",
11
+ min: 0,
12
+ max: 479
13
+ },
14
+ // phablet
15
+ xs: {
16
+ gridItemGutter: "var(--ds-space-200, 16px)",
17
+ gridMargin: "var(--ds-space-200, 16px)",
18
+ min: 480,
19
+ max: 767
20
+ },
21
+ // tablet
22
+ sm: {
23
+ gridItemGutter: "var(--ds-space-200, 16px)",
24
+ gridMargin: "var(--ds-space-300, 24px)",
25
+ min: 768,
26
+ max: 1023
27
+ },
28
+ // laptop desktop
29
+ md: {
30
+ gridItemGutter: "var(--ds-space-300, 24px)",
31
+ gridMargin: "var(--ds-space-400, 32px)",
32
+ min: 1024,
33
+ max: 1439
34
+ },
35
+ // monitor
36
+ lg: {
37
+ gridItemGutter: "var(--ds-space-400, 32px)",
38
+ gridMargin: "var(--ds-space-400, 32px)",
39
+ min: 1440,
40
+ max: 1767
41
+ },
42
+ // large high res
43
+ xl: {
44
+ gridItemGutter: "var(--ds-space-400, 32px)",
45
+ gridMargin: "var(--ds-space-500, 40px)",
46
+ min: 1768,
47
+ max: 2159
48
+ },
49
+ // extra large high res
50
+ xxl: {
51
+ gridItemGutter: "var(--ds-space-500, 40px)",
52
+ gridMargin: "var(--ds-space-500, 40px)",
53
+ min: 2160,
54
+ max: Number.MAX_SAFE_INTEGER
55
+ }
56
+ };
57
+
58
+ /**
59
+ * The list of breakpoints in order from smallest to largest. You may need to clone and reverse this list if you want the opposite.
60
+ *
61
+ * This is intentional for cascading with `min-width` or `media.above`. Media queries go from lowest width to highest.
62
+ *
63
+ * @experimental Unsafe for consumption outside of the design system itself.
64
+ */
65
+ export var UNSAFE_BREAKPOINTS_ORDERED_LIST = Object.keys(UNSAFE_BREAKPOINTS_CONFIG).sort(function (a, b) {
66
+ return UNSAFE_BREAKPOINTS_CONFIG[a].min - UNSAFE_BREAKPOINTS_CONFIG[b].min;
67
+ });
68
+
69
+ /**
70
+ * This is our smallest breakpoint with a few nuances to it:
71
+ * 1. It is the default value for shorthands, eg. `<GridItem span={6} />` maps to `{ [SMALLEST_BREAKPOINT]: props.span }`
72
+ * 2. It's omitted in `media.below` as there's nothing below `0px`.
73
+ *
74
+ * @experimental There's a chance this will change in _value_, but should only be used in a way that it will not matter if this value changes.
75
+ */
76
+ export var SMALLEST_BREAKPOINT = UNSAFE_BREAKPOINTS_ORDERED_LIST[0];
@@ -0,0 +1,3 @@
1
+ export { UNSAFE_media } from './media-helper';
2
+ export { UNSAFE_buildAboveMediaQueryCSS, UNSAFE_buildBelowMediaQueryCSS } from './build-media-query-css';
3
+ export { UNSAFE_BREAKPOINTS_ORDERED_LIST, UNSAFE_BREAKPOINTS_CONFIG } from './constants';
@@ -0,0 +1,78 @@
1
+ import { UNSAFE_BREAKPOINTS_CONFIG } from './constants';
2
+
3
+ /**
4
+ * To ensure min-width and max-width do both target at the same time, we subtract a value.
5
+ * We use a fractional value here as used in other libraries and described in @link https://www.w3.org/TR/mediaqueries-4/#mq-min-max: "…possibility of fractional viewport sizes which can occur as a result of non-integer pixel densities…"
6
+ */
7
+ var BELOW_PRECISION = 0.02;
8
+
9
+ /**
10
+ * This is the full internal version. The import has been separated to only expose as-needed.
11
+ */
12
+ var internalMedia = {
13
+ /**
14
+ * A media query to target viewports above the min width of a given breakpoint.
15
+ * Note that `media.above.xs` is redundant and should not be used, but it's included for programatic purposes.
16
+ */
17
+ above: {
18
+ /**
19
+ * `above.xxs` is redundant and no media query should be used, but it's included for programatic purposes…
20
+ *
21
+ * Eg. this is `@media (min-width: 0px)`
22
+ */
23
+ xxs: "@media (min-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.xxs.min, "px)"),
24
+ xs: "@media (min-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.xs.min, "px)"),
25
+ sm: "@media (min-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.sm.min, "px)"),
26
+ md: "@media (min-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.md.min, "px)"),
27
+ lg: "@media (min-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.lg.min, "px)"),
28
+ xl: "@media (min-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.xl.min, "px)"),
29
+ xxl: "@media (min-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.xxl.min, "px)")
30
+ },
31
+ below: {
32
+ /**
33
+ * A media query to target viewports below the min width of a given breakpoint.
34
+ * Note that `media.below.xxs` is intentionally omitted as this would be `@media (max-width: 0px)`
35
+ */
36
+ xs: "@media (max-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.xs.min - BELOW_PRECISION, "px)"),
37
+ sm: "@media (max-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.sm.min - BELOW_PRECISION, "px)"),
38
+ md: "@media (max-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.md.min - BELOW_PRECISION, "px)"),
39
+ lg: "@media (max-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.lg.min - BELOW_PRECISION, "px)"),
40
+ xl: "@media (max-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.xl.min - BELOW_PRECISION, "px)"),
41
+ xxl: "@media (max-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.xxl.min - BELOW_PRECISION, "px)")
42
+ },
43
+ /**
44
+ * A media query to target viewports exactly between the min and max of a given breakpoint.
45
+ */
46
+ only: {
47
+ xxs: "@media (min-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.xxs.min, "px) and (max-width: ").concat(UNSAFE_BREAKPOINTS_CONFIG.xxs.max, "px)"),
48
+ xs: "@media (min-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.xs.min, "px) and (max-width: ").concat(UNSAFE_BREAKPOINTS_CONFIG.xs.max, "px)"),
49
+ sm: "@media (min-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.sm.min, "px) and (max-width: ").concat(UNSAFE_BREAKPOINTS_CONFIG.sm.max, "px)"),
50
+ md: "@media (min-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.md.min, "px) and (max-width: ").concat(UNSAFE_BREAKPOINTS_CONFIG.md.max, "px)"),
51
+ lg: "@media (min-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.lg.min, "px) and (max-width: ").concat(UNSAFE_BREAKPOINTS_CONFIG.lg.max, "px)"),
52
+ xl: "@media (min-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.xl.min, "px) and (max-width: ").concat(UNSAFE_BREAKPOINTS_CONFIG.xl.max, "px)"),
53
+ xxl: "@media (min-width: ".concat(UNSAFE_BREAKPOINTS_CONFIG.xxl.min, "px) and (max-width: ").concat(UNSAFE_BREAKPOINTS_CONFIG.xxl.max, "px)")
54
+ }
55
+ };
56
+
57
+ /**
58
+ * This is an object of usable media query helpers using our internal breakpoints configuration.
59
+ *
60
+ * @experimental Unsafe for usage as the API is not finalized.
61
+ */
62
+ export var UNSAFE_media = {
63
+ above: internalMedia.above,
64
+ below: internalMedia.below
65
+ };
66
+
67
+ /**
68
+ * With these types:
69
+ * ```
70
+ * type MediaQuery = `@media (${string})`;
71
+ * type ResponsiveMediaObject = Record<Breakpoint, MediaQuery>;
72
+ * ```
73
+ *
74
+ * TODO: This `media` object as of typescript@4.9, would benefit from satisfies, eg.:
75
+ * ```
76
+ * const UNSAFE_media = { … } satisfies Record<'above' | 'only', ResponsiveMediaObject> & { below: Omit<ResponsiveMediaObject, 'xxs'> }
77
+ * ```
78
+ */
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/primitives",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,57 @@
1
+ import { CSSObject } from '@emotion/react';
2
+ import { SMALLEST_BREAKPOINT } from './constants';
3
+ import type { Breakpoint } from './types';
4
+ /**
5
+ * Build a map of breakpoints to css with media queries and nested styles.
6
+ *
7
+ * @experimental Unsafe for usage as the API is not finalized.
8
+ *
9
+ * @example
10
+ * A map to build optional `display:none` for consumption on a div.
11
+ * ```ts
12
+ * const hideMediaQueries = buildAboveMediaQueryCSS({ display: 'none' });
13
+ *
14
+ * const Component = ({ hideAtBreakpoints: ('xs' | 'sm')[], children: ReactNode }) => {
15
+ * return <div css={hideAtBreakpoints.map(b => hideMediaQueries[b])}>{children}</div>;
16
+ * }
17
+ * ```
18
+ *
19
+ * This roughly builds a map that will look roughly like this (if done manually):
20
+ * ```ts
21
+ * {
22
+ * xxs: css({ '@media (min-width: 0px)': { display: 'none' } }),
23
+ * xs: css({ '@media (min-width: …px)': { display: 'none' } }),
24
+ * sm: css({ '@media (min-width: …px)': { display: 'none' } }),
25
+ * }
26
+ * ```
27
+ */
28
+ export declare const UNSAFE_buildAboveMediaQueryCSS: (input: CSSObject | ((breakpoint: Breakpoint) => CSSObject)) => Required<Partial<Record<Breakpoint, import("@emotion/react").SerializedStyles>>>;
29
+ /**
30
+ * Build a map of breakpoints to css with media queries and nested styles.
31
+ *
32
+ * WARNING: The smallest breakpoint is not a valid key as a media query below 0px is misleading.
33
+ * This is separated from `buildAboveMediaQueryCSS` for that specific reason, you cannot have type safety with this variance.
34
+ *
35
+ * @experimental Unsafe for usage as the API is not finalized.
36
+ *
37
+ * @example
38
+ * A map to build optional `display:none` for consumption on a div.
39
+ * ```ts
40
+ * const hideMediaQueries = buildBelowMediaQueryCSS({ display: 'none' });
41
+ *
42
+ * const Component = ({ hideAtBreakpoints: ('xs' | 'sm')[], children: ReactNode }) => {
43
+ * return <div css={hideAtBreakpoints.map(b => hideMediaQueries[b])}>{children}</div>;
44
+ * }
45
+ * ```
46
+ *
47
+ * This roughly builds a map that will look roughly like this (if done manually):
48
+ * ```ts
49
+ * {
50
+ * xs: css({ '@media (max-width: …px)': { display: 'none' } }),
51
+ * sm: css({ '@media (max-width: …px)': { display: 'none' } }),
52
+ * }
53
+ * ```
54
+ *
55
+ * @experimental Unsafe for usage as the API is not finalized.
56
+ */
57
+ export declare const UNSAFE_buildBelowMediaQueryCSS: (input: CSSObject | ((breakpoint: Exclude<Breakpoint, typeof SMALLEST_BREAKPOINT>) => CSSObject)) => Required<Omit<Partial<Record<Breakpoint, import("@emotion/react").SerializedStyles>>, "xxs">>;
@@ -0,0 +1,23 @@
1
+ import type { Breakpoint, BreakpointConfig } from './types';
2
+ /**
3
+ * Our internal configuration for breakpoints configuration.
4
+ *
5
+ * @experimental Unsafe for consumption outside of the design system itself.
6
+ */
7
+ export declare const UNSAFE_BREAKPOINTS_CONFIG: Record<Breakpoint, BreakpointConfig>;
8
+ /**
9
+ * The list of breakpoints in order from smallest to largest. You may need to clone and reverse this list if you want the opposite.
10
+ *
11
+ * This is intentional for cascading with `min-width` or `media.above`. Media queries go from lowest width to highest.
12
+ *
13
+ * @experimental Unsafe for consumption outside of the design system itself.
14
+ */
15
+ export declare const UNSAFE_BREAKPOINTS_ORDERED_LIST: ["xxs", "xs", "sm", "md", "lg", "xl", "xxl"];
16
+ /**
17
+ * This is our smallest breakpoint with a few nuances to it:
18
+ * 1. It is the default value for shorthands, eg. `<GridItem span={6} />` maps to `{ [SMALLEST_BREAKPOINT]: props.span }`
19
+ * 2. It's omitted in `media.below` as there's nothing below `0px`.
20
+ *
21
+ * @experimental There's a chance this will change in _value_, but should only be used in a way that it will not matter if this value changes.
22
+ */
23
+ export declare const SMALLEST_BREAKPOINT: "xxs";
@@ -0,0 +1,4 @@
1
+ export { UNSAFE_media } from './media-helper';
2
+ export { UNSAFE_buildAboveMediaQueryCSS, UNSAFE_buildBelowMediaQueryCSS, } from './build-media-query-css';
3
+ export { UNSAFE_BREAKPOINTS_ORDERED_LIST, UNSAFE_BREAKPOINTS_CONFIG, } from './constants';
4
+ export type { Breakpoint, ResponsiveObject, ResponsiveCSSObject, } from './types';
@@ -0,0 +1,45 @@
1
+ /**
2
+ * This is an object of usable media query helpers using our internal breakpoints configuration.
3
+ *
4
+ * @experimental Unsafe for usage as the API is not finalized.
5
+ */
6
+ export declare const UNSAFE_media: {
7
+ readonly above: {
8
+ /**
9
+ * `above.xxs` is redundant and no media query should be used, but it's included for programatic purposes…
10
+ *
11
+ * Eg. this is `@media (min-width: 0px)`
12
+ */
13
+ readonly xxs: `@media (min-width: ${number}px)`;
14
+ readonly xs: `@media (min-width: ${number}px)`;
15
+ readonly sm: `@media (min-width: ${number}px)`;
16
+ readonly md: `@media (min-width: ${number}px)`;
17
+ readonly lg: `@media (min-width: ${number}px)`;
18
+ readonly xl: `@media (min-width: ${number}px)`;
19
+ readonly xxl: `@media (min-width: ${number}px)`;
20
+ };
21
+ readonly below: {
22
+ /**
23
+ * A media query to target viewports below the min width of a given breakpoint.
24
+ * Note that `media.below.xxs` is intentionally omitted as this would be `@media (max-width: 0px)`
25
+ */
26
+ readonly xs: `@media (max-width: ${number}px)`;
27
+ readonly sm: `@media (max-width: ${number}px)`;
28
+ readonly md: `@media (max-width: ${number}px)`;
29
+ readonly lg: `@media (max-width: ${number}px)`;
30
+ readonly xl: `@media (max-width: ${number}px)`;
31
+ readonly xxl: `@media (max-width: ${number}px)`;
32
+ };
33
+ };
34
+ /**
35
+ * With these types:
36
+ * ```
37
+ * type MediaQuery = `@media (${string})`;
38
+ * type ResponsiveMediaObject = Record<Breakpoint, MediaQuery>;
39
+ * ```
40
+ *
41
+ * TODO: This `media` object as of typescript@4.9, would benefit from satisfies, eg.:
42
+ * ```
43
+ * const UNSAFE_media = { … } satisfies Record<'above' | 'only', ResponsiveMediaObject> & { below: Omit<ResponsiveMediaObject, 'xxs'> }
44
+ * ```
45
+ */
@@ -0,0 +1,47 @@
1
+ import { css } from '@emotion/react';
2
+ import { token } from '@atlaskit/tokens';
3
+ /**
4
+ * The breakpoints we have for responsiveness.
5
+ */
6
+ export declare type Breakpoint = 'xxs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
7
+ /**
8
+ * An object type mapping a value to each breakpoint (optionally)
9
+ */
10
+ export declare type ResponsiveObject<T> = Partial<Record<Breakpoint, T>>;
11
+ /**
12
+ * A map of breakpoints to CSS, commonly used to build maps given a responsive object
13
+ * so we can statically compile CSS upfront, but dynamically apply it.
14
+ *
15
+ * @example Here we could conditionally load margins based a `setMarginBreakpoints={['xs', 'md']}` type prop.
16
+ * ```tsx
17
+ * const marginMediaQueries = {
18
+ * xxs: css({ [media.above.xxs]: margin: 0 } }),
19
+ * xs: css({ [media.above.xs]: margin: 4 } }),
20
+ * //…
21
+ * }
22
+ *
23
+ * return <div css={setMarginBreakpoints.map(breakpoint => marginMediaQueries[breakpoint])} />
24
+ * ```
25
+ */
26
+ export declare type ResponsiveCSSObject = ResponsiveObject<ReturnType<typeof css>>;
27
+ /**
28
+ * Our internal breakpoint config used to build media queries and define attributes for certain components.
29
+ */
30
+ export declare type BreakpointConfig = {
31
+ /**
32
+ * The gap between a `GridItem`.
33
+ */
34
+ gridItemGutter: ReturnType<typeof token>;
35
+ /**
36
+ * The outer whitespace of a `Grid` item.
37
+ */
38
+ gridMargin: ReturnType<typeof token>;
39
+ /**
40
+ * The min-width used in media queries
41
+ */
42
+ min: number;
43
+ /**
44
+ * The max-width used in media queries
45
+ */
46
+ max: number;
47
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/primitives",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Primitives are token-backed low-level building blocks.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,7 +34,8 @@
34
34
  ".": "./src/index.tsx",
35
35
  "./box": "./src/components/box.tsx",
36
36
  "./stack": "./src/components/stack.partial.tsx",
37
- "./inline": "./src/components/inline.partial.tsx"
37
+ "./inline": "./src/components/inline.partial.tsx",
38
+ "./responsive": "./src/helpers/responsive/index.tsx"
38
39
  },
39
40
  "dependencies": {
40
41
  "@atlaskit/ds-explorations": "*",
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@atlaskit/primitives/responsive",
3
+ "main": "../dist/cjs/helpers/responsive/index.js",
4
+ "module": "../dist/esm/helpers/responsive/index.js",
5
+ "module:es2019": "../dist/es2019/helpers/responsive/index.js",
6
+ "sideEffects": false,
7
+ "types": "../dist/types/helpers/responsive/index.d.ts",
8
+ "typesVersions": {
9
+ ">=4.0 <4.5": {
10
+ "*": [
11
+ "../dist/types-ts4.0/helpers/responsive/index.d.ts"
12
+ ]
13
+ }
14
+ }
15
+ }