@atlaskit/primitives 0.2.2 → 0.3.1

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/components/internal/base-box.partial.js +42 -42
  3. package/dist/cjs/constants.js +0 -13
  4. package/dist/cjs/helpers/responsive/build-media-query-css.js +88 -0
  5. package/dist/cjs/helpers/responsive/constants.js +85 -0
  6. package/dist/cjs/helpers/responsive/index.js +38 -0
  7. package/dist/cjs/helpers/responsive/media-helper.js +84 -0
  8. package/dist/cjs/helpers/responsive/types.js +5 -0
  9. package/dist/cjs/version.json +1 -1
  10. package/dist/es2019/components/internal/base-box.partial.js +9 -15
  11. package/dist/es2019/constants.js +1 -3
  12. package/dist/es2019/helpers/responsive/build-media-query-css.js +85 -0
  13. package/dist/es2019/helpers/responsive/constants.js +74 -0
  14. package/dist/es2019/helpers/responsive/index.js +3 -0
  15. package/dist/es2019/helpers/responsive/media-helper.js +78 -0
  16. package/dist/es2019/helpers/responsive/types.js +1 -0
  17. package/dist/es2019/version.json +1 -1
  18. package/dist/esm/components/internal/base-box.partial.js +43 -43
  19. package/dist/esm/constants.js +1 -3
  20. package/dist/esm/helpers/responsive/build-media-query-css.js +79 -0
  21. package/dist/esm/helpers/responsive/constants.js +76 -0
  22. package/dist/esm/helpers/responsive/index.js +3 -0
  23. package/dist/esm/helpers/responsive/media-helper.js +78 -0
  24. package/dist/esm/helpers/responsive/types.js +1 -0
  25. package/dist/esm/version.json +1 -1
  26. package/dist/types/components/internal/base-box.partial.d.ts +11 -10
  27. package/dist/types/components/internal/types.d.ts +5 -3
  28. package/dist/types/constants.d.ts +0 -2
  29. package/dist/types/helpers/responsive/build-media-query-css.d.ts +57 -0
  30. package/dist/types/helpers/responsive/constants.d.ts +23 -0
  31. package/dist/types/helpers/responsive/index.d.ts +4 -0
  32. package/dist/types/helpers/responsive/media-helper.d.ts +45 -0
  33. package/dist/types/helpers/responsive/types.d.ts +47 -0
  34. package/package.json +3 -3
  35. package/report.api.md +15 -20
  36. package/responsive/package.json +15 -0
  37. package/tmp/api-report-tmp.d.ts +15 -10
@@ -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.1",
4
4
  "sideEffects": false
5
5
  }
@@ -8,16 +8,16 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
8
8
  import { forwardRef } from 'react';
9
9
  import { css, jsx } from '@emotion/react';
10
10
  import invariant from 'tiny-invariant';
11
- import { BREAKPOINTS_CONFIG, BREAKPOINTS_LIST, LAYERS } from '../../constants';
11
+ import { LAYERS } from '../../constants';
12
+ import { UNSAFE_buildAboveMediaQueryCSS } from '../../helpers/responsive';
12
13
  import { BOX_RESPONSIVE_PROPS } from './types';
13
14
  import { isResponsiveStyleProp, isStaticStyleProp } from './utils';
14
15
  var responsiveRules = BOX_RESPONSIVE_PROPS.reduce(function (mapping, cssProperty) {
15
- return Object.assign(mapping, _defineProperty({}, cssProperty, BREAKPOINTS_LIST.reduce(function (configs, breakpoint) {
16
- var config = BREAKPOINTS_CONFIG[breakpoint];
17
- return Object.assign(configs, _defineProperty({}, breakpoint, css(_defineProperty({}, "@media (min-width: ".concat(config.min, "px)"), _defineProperty({}, cssProperty, "var(--ds-box-responsive-".concat(cssProperty, "-").concat(breakpoint, ")"))))));
18
- }, {
16
+ return Object.assign(mapping, _defineProperty({}, cssProperty, _objectSpread({
19
17
  static: css(_defineProperty({}, cssProperty, "var(--ds-box-static-".concat(cssProperty, ")")))
20
- })));
18
+ }, UNSAFE_buildAboveMediaQueryCSS(function (breakpoint) {
19
+ return _defineProperty({}, cssProperty, "var(--ds-box-responsive-".concat(cssProperty, "-").concat(breakpoint, ")"));
20
+ }))));
21
21
  }, {});
22
22
  var getResponsiveVars = function getResponsiveVars(propertyName, propertyValue, mapping) {
23
23
  if (isResponsiveStyleProp(propertyValue)) {
@@ -31,8 +31,8 @@ var getResponsiveVars = function getResponsiveVars(propertyName, propertyValue,
31
31
  var getResponsiveStyles = function getResponsiveStyles(propertyName, propertyValue) {
32
32
  invariant(typeof responsiveRules[propertyName] !== 'undefined', "Responsive rules for \"".concat(propertyName, "\" have not been statically defined."));
33
33
  if (isResponsiveStyleProp(propertyValue)) {
34
- return Object.keys(propertyValue).map(function (responsiveProp) {
35
- return responsiveRules[propertyName][responsiveProp];
34
+ return Object.keys(propertyValue).map(function (breakpoint) {
35
+ return responsiveRules[propertyName][breakpoint];
36
36
  });
37
37
  } else if (isStaticStyleProp(propertyValue)) {
38
38
  return responsiveRules[propertyName].static;
@@ -49,41 +49,41 @@ var getResponsiveStyles = function getResponsiveStyles(propertyName, propertyVal
49
49
  *
50
50
  * @internal
51
51
  */
52
- export var BaseBox = /*#__PURE__*/forwardRef(function (_ref2, ref) {
53
- var as = _ref2.as,
54
- className = _ref2.className,
55
- children = _ref2.children,
56
- color = _ref2.color,
57
- backgroundColor = _ref2.backgroundColor,
58
- shadow = _ref2.shadow,
59
- borderStyle = _ref2.borderStyle,
60
- borderWidth = _ref2.borderWidth,
61
- borderRadius = _ref2.borderRadius,
62
- borderColor = _ref2.borderColor,
63
- layer = _ref2.layer,
64
- flex = _ref2.flex,
65
- flexGrow = _ref2.flexGrow,
66
- flexShrink = _ref2.flexShrink,
67
- alignSelf = _ref2.alignSelf,
68
- overflow = _ref2.overflow,
69
- overflowInline = _ref2.overflowInline,
70
- overflowBlock = _ref2.overflowBlock,
71
- padding = _ref2.padding,
72
- paddingBlock = _ref2.paddingBlock,
73
- paddingBlockStart = _ref2.paddingBlockStart,
74
- paddingBlockEnd = _ref2.paddingBlockEnd,
75
- paddingInline = _ref2.paddingInline,
76
- paddingInlineStart = _ref2.paddingInlineStart,
77
- paddingInlineEnd = _ref2.paddingInlineEnd,
78
- height = _ref2.height,
79
- width = _ref2.width,
80
- _ref2$display = _ref2.display,
81
- display = _ref2$display === void 0 ? displayMap.block : _ref2$display,
82
- _ref2$position = _ref2.position,
83
- position = _ref2$position === void 0 ? 'static' : _ref2$position,
84
- UNSAFE_style = _ref2.UNSAFE_style,
85
- testId = _ref2.testId,
86
- htmlAttributes = _objectWithoutProperties(_ref2, _excluded);
52
+ export var BaseBox = /*#__PURE__*/forwardRef(function (_ref3, ref) {
53
+ var as = _ref3.as,
54
+ className = _ref3.className,
55
+ children = _ref3.children,
56
+ color = _ref3.color,
57
+ backgroundColor = _ref3.backgroundColor,
58
+ shadow = _ref3.shadow,
59
+ borderStyle = _ref3.borderStyle,
60
+ borderWidth = _ref3.borderWidth,
61
+ borderRadius = _ref3.borderRadius,
62
+ borderColor = _ref3.borderColor,
63
+ layer = _ref3.layer,
64
+ flex = _ref3.flex,
65
+ flexGrow = _ref3.flexGrow,
66
+ flexShrink = _ref3.flexShrink,
67
+ alignSelf = _ref3.alignSelf,
68
+ overflow = _ref3.overflow,
69
+ overflowInline = _ref3.overflowInline,
70
+ overflowBlock = _ref3.overflowBlock,
71
+ padding = _ref3.padding,
72
+ paddingBlock = _ref3.paddingBlock,
73
+ paddingBlockStart = _ref3.paddingBlockStart,
74
+ paddingBlockEnd = _ref3.paddingBlockEnd,
75
+ paddingInline = _ref3.paddingInline,
76
+ paddingInlineStart = _ref3.paddingInlineStart,
77
+ paddingInlineEnd = _ref3.paddingInlineEnd,
78
+ height = _ref3.height,
79
+ width = _ref3.width,
80
+ _ref3$display = _ref3.display,
81
+ display = _ref3$display === void 0 ? displayMap.block : _ref3$display,
82
+ _ref3$position = _ref3.position,
83
+ position = _ref3$position === void 0 ? 'static' : _ref3$position,
84
+ UNSAFE_style = _ref3.UNSAFE_style,
85
+ testId = _ref3.testId,
86
+ htmlAttributes = _objectWithoutProperties(_ref3, _excluded);
87
87
  var Component = as || 'div';
88
88
  var inlineStyles = Object.assign({}, UNSAFE_style, getResponsiveVars('borderWidth', borderWidth, borderWidthMap), getResponsiveVars('display', display, displayMap), getResponsiveVars('padding', padding, paddingMap), getResponsiveVars('paddingBlock', paddingBlock, paddingMap), getResponsiveVars('paddingBlockStart', paddingBlockStart, paddingMap), getResponsiveVars('paddingBlockEnd', paddingBlockEnd, paddingMap), getResponsiveVars('paddingInline', paddingInline, paddingMap), getResponsiveVars('paddingInlineStart', paddingInlineStart, paddingMap), getResponsiveVars('paddingInlineEnd', paddingInlineEnd, paddingMap));
89
89
  var node = jsx(Component, _extends({
@@ -1,4 +1,3 @@
1
- import { UNSAFE_Breakpoint as Breakpoint, UNSAFE_BreakpointConfig as BreakpointConfig, UNSAFE_BREAKPOINTS_CONFIG as BREAKPOINTS_CONFIG, UNSAFE_BREAKPOINTS_LIST as BREAKPOINTS_LIST } from '@atlaskit/ds-explorations';
2
1
  export var LAYERS = {
3
2
  card: 100,
4
3
  navigation: 200,
@@ -9,5 +8,4 @@ export var LAYERS = {
9
8
  flag: 600,
10
9
  spotlight: 700,
11
10
  tooltip: 800
12
- };
13
- export { BREAKPOINTS_CONFIG, BREAKPOINTS_LIST };
11
+ };
@@ -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.1",
4
4
  "sideEffects": false
5
5
  }
@@ -1,6 +1,7 @@
1
1
  /** @jsx jsx */
2
2
  import { ComponentPropsWithoutRef, ComponentPropsWithRef, ElementType, FC, ReactElement, ReactNode } from 'react';
3
- import { Breakpoint, Layer } from '../../constants';
3
+ import { Layer } from '../../constants';
4
+ import { ResponsiveObject } from '../../helpers/responsive';
4
5
  import type { BasePrimitiveProps } from '../types';
5
6
  export declare type BaseBoxProps<T extends ElementType = 'div'> = Omit<ComponentPropsWithoutRef<T>, 'as' | 'className' | 'style'> & BasePrimitiveProps & BaseBoxPropsFoundation<T>;
6
7
  declare type BaseBoxPropsFoundation<T extends ElementType> = {
@@ -43,7 +44,7 @@ declare type BaseBoxPropsFoundation<T extends ElementType> = {
43
44
  /**
44
45
  * Defines border width.
45
46
  */
46
- borderWidth?: BorderWidth | Partial<Record<Breakpoint, BorderWidth>>;
47
+ borderWidth?: BorderWidth | ResponsiveObject<BorderWidth>;
47
48
  /**
48
49
  * Token representing border color with a fallback.
49
50
  */
@@ -94,37 +95,37 @@ declare type BaseBoxPropsFoundation<T extends ElementType> = {
94
95
  * @see paddingBlock
95
96
  * @see paddingInline
96
97
  */
97
- padding?: Padding | Partial<Record<Breakpoint, Padding>>;
98
+ padding?: Padding | ResponsiveObject<Padding>;
98
99
  /**
99
100
  * Tokens representing CSS shorthand `paddingBlock`.
100
101
  *
101
102
  * @see paddingBlockStart
102
103
  * @see paddingBlockEnd
103
104
  */
104
- paddingBlock?: PaddingBlock | Partial<Record<Breakpoint, PaddingBlock>>;
105
+ paddingBlock?: PaddingBlock | ResponsiveObject<PaddingBlock>;
105
106
  /**
106
107
  * Tokens representing CSS `paddingBlockStart`.
107
108
  */
108
- paddingBlockStart?: PaddingBlockStart | Partial<Record<Breakpoint, PaddingBlockStart>>;
109
+ paddingBlockStart?: PaddingBlockStart | ResponsiveObject<PaddingBlockStart>;
109
110
  /**
110
111
  * Tokens representing CSS `paddingBlockEnd`.
111
112
  */
112
- paddingBlockEnd?: PaddingBlockEnd | Partial<Record<Breakpoint, PaddingBlockEnd>>;
113
+ paddingBlockEnd?: PaddingBlockEnd | ResponsiveObject<PaddingBlockEnd>;
113
114
  /**
114
115
  * Tokens representing CSS shorthand `paddingInline`.
115
116
  *
116
117
  * @see paddingInlineStart
117
118
  * @see paddingInlineEnd
118
119
  */
119
- paddingInline?: PaddingInline | Partial<Record<Breakpoint, PaddingInline>>;
120
+ paddingInline?: PaddingInline | ResponsiveObject<PaddingInline>;
120
121
  /**
121
122
  * Tokens representing CSS `paddingInlineStart`.
122
123
  */
123
- paddingInlineStart?: PaddingInlineStart | Partial<Record<Breakpoint, PaddingInlineStart>>;
124
+ paddingInlineStart?: PaddingInlineStart | ResponsiveObject<PaddingInlineStart>;
124
125
  /**
125
126
  * Tokens representing CSS `paddingInlineEnd`.
126
127
  */
127
- paddingInlineEnd?: PaddingInlineEnd | Partial<Record<Breakpoint, PaddingInlineEnd>>;
128
+ paddingInlineEnd?: PaddingInlineEnd | ResponsiveObject<PaddingInlineEnd>;
128
129
  /**
129
130
  * Token representing width.
130
131
  * @experimental The existing tokens will be replaced to better reflect dimensions.
@@ -138,7 +139,7 @@ declare type BaseBoxPropsFoundation<T extends ElementType> = {
138
139
  /**
139
140
  * Defines display type and layout. Defaults to `block`.
140
141
  */
141
- display?: Display | Partial<Record<Breakpoint, Display>>;
142
+ display?: Display | ResponsiveObject<Display>;
142
143
  /**
143
144
  * CSS position property.
144
145
  */
@@ -1,6 +1,8 @@
1
1
  import { SerializedStyles } from '@emotion/react';
2
- import { Breakpoint } from '../../constants';
2
+ import { ResponsiveCSSObject, ResponsiveObject } from '../../helpers/responsive';
3
3
  export declare const BOX_RESPONSIVE_PROPS: readonly ["borderWidth", "display", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd"];
4
4
  export declare type BoxResponsiveProp = typeof BOX_RESPONSIVE_PROPS[number];
5
- export declare type BreakpointIndexedStyle = Record<Breakpoint | 'static', SerializedStyles>;
6
- export declare type GenericPropertyValue = string | Partial<Record<Breakpoint, string>> | undefined;
5
+ export declare type StaticResponsiveCSSObject = ResponsiveCSSObject & {
6
+ static: SerializedStyles;
7
+ };
8
+ export declare type GenericPropertyValue = string | ResponsiveObject<string> | undefined;
@@ -1,4 +1,3 @@
1
- import { UNSAFE_Breakpoint as Breakpoint, UNSAFE_BreakpointConfig as BreakpointConfig, UNSAFE_BREAKPOINTS_CONFIG as BREAKPOINTS_CONFIG, UNSAFE_BREAKPOINTS_LIST as BREAKPOINTS_LIST } from '@atlaskit/ds-explorations';
2
1
  export declare const LAYERS: {
3
2
  readonly card: 100;
4
3
  readonly navigation: 200;
@@ -11,4 +10,3 @@ export declare const LAYERS: {
11
10
  readonly tooltip: 800;
12
11
  };
13
12
  export declare type Layer = keyof typeof LAYERS;
14
- export { BREAKPOINTS_CONFIG, BREAKPOINTS_LIST, type Breakpoint, type BreakpointConfig, };