@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/primitives
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`114d6a73f72`](https://bitbucket.org/atlassian/atlassian-frontend/commits/114d6a73f72) - Cleanup the experimental responsive box utilizing our responsive helpers.
8
+
9
+ ## 0.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [`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.
14
+
3
15
  ## 0.2.2
4
16
 
5
17
  ### Patch Changes
@@ -12,18 +12,18 @@ var _react = require("react");
12
12
  var _react2 = require("@emotion/react");
13
13
  var _tinyInvariant = _interopRequireDefault(require("tiny-invariant"));
14
14
  var _constants = require("../../constants");
15
+ var _responsive = require("../../helpers/responsive");
15
16
  var _types = require("./types");
16
17
  var _utils = require("./utils");
17
18
  var _excluded = ["as", "className", "children", "color", "backgroundColor", "shadow", "borderStyle", "borderWidth", "borderRadius", "borderColor", "layer", "flex", "flexGrow", "flexShrink", "alignSelf", "overflow", "overflowInline", "overflowBlock", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "height", "width", "display", "position", "UNSAFE_style", "testId"];
18
19
  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; }
19
20
  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; }
20
21
  var responsiveRules = _types.BOX_RESPONSIVE_PROPS.reduce(function (mapping, cssProperty) {
21
- return Object.assign(mapping, (0, _defineProperty2.default)({}, cssProperty, _constants.BREAKPOINTS_LIST.reduce(function (configs, breakpoint) {
22
- var config = _constants.BREAKPOINTS_CONFIG[breakpoint];
23
- return Object.assign(configs, (0, _defineProperty2.default)({}, breakpoint, (0, _react2.css)((0, _defineProperty2.default)({}, "@media (min-width: ".concat(config.min, "px)"), (0, _defineProperty2.default)({}, cssProperty, "var(--ds-box-responsive-".concat(cssProperty, "-").concat(breakpoint, ")"))))));
24
- }, {
22
+ return Object.assign(mapping, (0, _defineProperty2.default)({}, cssProperty, _objectSpread({
25
23
  static: (0, _react2.css)((0, _defineProperty2.default)({}, cssProperty, "var(--ds-box-static-".concat(cssProperty, ")")))
26
- })));
24
+ }, (0, _responsive.UNSAFE_buildAboveMediaQueryCSS)(function (breakpoint) {
25
+ return (0, _defineProperty2.default)({}, cssProperty, "var(--ds-box-responsive-".concat(cssProperty, "-").concat(breakpoint, ")"));
26
+ }))));
27
27
  }, {});
28
28
  var getResponsiveVars = function getResponsiveVars(propertyName, propertyValue, mapping) {
29
29
  if ((0, _utils.isResponsiveStyleProp)(propertyValue)) {
@@ -37,8 +37,8 @@ var getResponsiveVars = function getResponsiveVars(propertyName, propertyValue,
37
37
  var getResponsiveStyles = function getResponsiveStyles(propertyName, propertyValue) {
38
38
  (0, _tinyInvariant.default)(typeof responsiveRules[propertyName] !== 'undefined', "Responsive rules for \"".concat(propertyName, "\" have not been statically defined."));
39
39
  if ((0, _utils.isResponsiveStyleProp)(propertyValue)) {
40
- return Object.keys(propertyValue).map(function (responsiveProp) {
41
- return responsiveRules[propertyName][responsiveProp];
40
+ return Object.keys(propertyValue).map(function (breakpoint) {
41
+ return responsiveRules[propertyName][breakpoint];
42
42
  });
43
43
  } else if ((0, _utils.isStaticStyleProp)(propertyValue)) {
44
44
  return responsiveRules[propertyName].static;
@@ -55,41 +55,41 @@ var getResponsiveStyles = function getResponsiveStyles(propertyName, propertyVal
55
55
  *
56
56
  * @internal
57
57
  */
58
- var BaseBox = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
59
- var as = _ref2.as,
60
- className = _ref2.className,
61
- children = _ref2.children,
62
- color = _ref2.color,
63
- backgroundColor = _ref2.backgroundColor,
64
- shadow = _ref2.shadow,
65
- borderStyle = _ref2.borderStyle,
66
- borderWidth = _ref2.borderWidth,
67
- borderRadius = _ref2.borderRadius,
68
- borderColor = _ref2.borderColor,
69
- layer = _ref2.layer,
70
- flex = _ref2.flex,
71
- flexGrow = _ref2.flexGrow,
72
- flexShrink = _ref2.flexShrink,
73
- alignSelf = _ref2.alignSelf,
74
- overflow = _ref2.overflow,
75
- overflowInline = _ref2.overflowInline,
76
- overflowBlock = _ref2.overflowBlock,
77
- padding = _ref2.padding,
78
- paddingBlock = _ref2.paddingBlock,
79
- paddingBlockStart = _ref2.paddingBlockStart,
80
- paddingBlockEnd = _ref2.paddingBlockEnd,
81
- paddingInline = _ref2.paddingInline,
82
- paddingInlineStart = _ref2.paddingInlineStart,
83
- paddingInlineEnd = _ref2.paddingInlineEnd,
84
- height = _ref2.height,
85
- width = _ref2.width,
86
- _ref2$display = _ref2.display,
87
- display = _ref2$display === void 0 ? displayMap.block : _ref2$display,
88
- _ref2$position = _ref2.position,
89
- position = _ref2$position === void 0 ? 'static' : _ref2$position,
90
- UNSAFE_style = _ref2.UNSAFE_style,
91
- testId = _ref2.testId,
92
- htmlAttributes = (0, _objectWithoutProperties2.default)(_ref2, _excluded);
58
+ var BaseBox = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
59
+ var as = _ref3.as,
60
+ className = _ref3.className,
61
+ children = _ref3.children,
62
+ color = _ref3.color,
63
+ backgroundColor = _ref3.backgroundColor,
64
+ shadow = _ref3.shadow,
65
+ borderStyle = _ref3.borderStyle,
66
+ borderWidth = _ref3.borderWidth,
67
+ borderRadius = _ref3.borderRadius,
68
+ borderColor = _ref3.borderColor,
69
+ layer = _ref3.layer,
70
+ flex = _ref3.flex,
71
+ flexGrow = _ref3.flexGrow,
72
+ flexShrink = _ref3.flexShrink,
73
+ alignSelf = _ref3.alignSelf,
74
+ overflow = _ref3.overflow,
75
+ overflowInline = _ref3.overflowInline,
76
+ overflowBlock = _ref3.overflowBlock,
77
+ padding = _ref3.padding,
78
+ paddingBlock = _ref3.paddingBlock,
79
+ paddingBlockStart = _ref3.paddingBlockStart,
80
+ paddingBlockEnd = _ref3.paddingBlockEnd,
81
+ paddingInline = _ref3.paddingInline,
82
+ paddingInlineStart = _ref3.paddingInlineStart,
83
+ paddingInlineEnd = _ref3.paddingInlineEnd,
84
+ height = _ref3.height,
85
+ width = _ref3.width,
86
+ _ref3$display = _ref3.display,
87
+ display = _ref3$display === void 0 ? displayMap.block : _ref3$display,
88
+ _ref3$position = _ref3.position,
89
+ position = _ref3$position === void 0 ? 'static' : _ref3$position,
90
+ UNSAFE_style = _ref3.UNSAFE_style,
91
+ testId = _ref3.testId,
92
+ htmlAttributes = (0, _objectWithoutProperties2.default)(_ref3, _excluded);
93
93
  var Component = as || 'div';
94
94
  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));
95
95
  var node = (0, _react2.jsx)(Component, (0, _extends2.default)({
@@ -3,20 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "BREAKPOINTS_CONFIG", {
7
- enumerable: true,
8
- get: function get() {
9
- return _dsExplorations.UNSAFE_BREAKPOINTS_CONFIG;
10
- }
11
- });
12
- Object.defineProperty(exports, "BREAKPOINTS_LIST", {
13
- enumerable: true,
14
- get: function get() {
15
- return _dsExplorations.UNSAFE_BREAKPOINTS_LIST;
16
- }
17
- });
18
6
  exports.LAYERS = void 0;
19
- var _dsExplorations = require("@atlaskit/ds-explorations");
20
7
  var LAYERS = {
21
8
  card: 100,
22
9
  navigation: 200,
@@ -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.1",
4
4
  "sideEffects": false
5
5
  }
@@ -3,26 +3,20 @@ import _extends from "@babel/runtime/helpers/extends";
3
3
  import { forwardRef } from 'react';
4
4
  import { css, jsx } from '@emotion/react';
5
5
  import invariant from 'tiny-invariant';
6
- import { BREAKPOINTS_CONFIG, BREAKPOINTS_LIST, LAYERS } from '../../constants';
6
+ import { LAYERS } from '../../constants';
7
+ import { UNSAFE_buildAboveMediaQueryCSS } from '../../helpers/responsive';
7
8
  import { BOX_RESPONSIVE_PROPS } from './types';
8
9
  import { isResponsiveStyleProp, isStaticStyleProp } from './utils';
9
10
  const responsiveRules = BOX_RESPONSIVE_PROPS.reduce((mapping, cssProperty) => {
10
11
  return Object.assign(mapping, {
11
- [cssProperty]: BREAKPOINTS_LIST.reduce((configs, breakpoint) => {
12
- const config = BREAKPOINTS_CONFIG[breakpoint];
13
- return Object.assign(configs, {
14
- [breakpoint]: css({
15
- // eslint-disable-next-line @repo/internal/styles/no-nested-styles
16
- [`@media (min-width: ${config.min}px)`]: {
17
- [cssProperty]: `var(--ds-box-responsive-${cssProperty}-${breakpoint})`
18
- }
19
- })
20
- });
21
- }, {
12
+ [cssProperty]: {
22
13
  static: css({
23
14
  [cssProperty]: `var(--ds-box-static-${cssProperty})`
24
- })
25
- })
15
+ }),
16
+ ...UNSAFE_buildAboveMediaQueryCSS(breakpoint => ({
17
+ [cssProperty]: `var(--ds-box-responsive-${cssProperty}-${breakpoint})`
18
+ }))
19
+ }
26
20
  });
27
21
  }, {});
28
22
  const getResponsiveVars = (propertyName, propertyValue, mapping) => {
@@ -40,7 +34,7 @@ const getResponsiveVars = (propertyName, propertyValue, mapping) => {
40
34
  const getResponsiveStyles = (propertyName, propertyValue) => {
41
35
  invariant(typeof responsiveRules[propertyName] !== 'undefined', `Responsive rules for "${propertyName}" have not been statically defined.`);
42
36
  if (isResponsiveStyleProp(propertyValue)) {
43
- return Object.keys(propertyValue).map(responsiveProp => responsiveRules[propertyName][responsiveProp]);
37
+ return Object.keys(propertyValue).map(breakpoint => responsiveRules[propertyName][breakpoint]);
44
38
  } else if (isStaticStyleProp(propertyValue)) {
45
39
  return responsiveRules[propertyName].static;
46
40
  }
@@ -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 const LAYERS = {
3
2
  card: 100,
4
3
  navigation: 200,
@@ -9,5 +8,4 @@ export const LAYERS = {
9
8
  flag: 600,
10
9
  spotlight: 700,
11
10
  tooltip: 800
12
- };
13
- export { BREAKPOINTS_CONFIG, BREAKPOINTS_LIST };
11
+ };
@@ -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
+ };