@atlaskit/primitives 1.20.0 → 2.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/primitives
2
2
 
3
+ ## 2.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 2.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - [#68009](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/68009) [`1168354ed6ef`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1168354ed6ef) - We now ensure the specificity of our `xcss`-based overrides are consistent across all primitives so `xcss` will always override props.
14
+
15
+ This resulted in a breaking change wtih Grid. For example, `<Grid templateAreas="…" xcss({ gridTemplateAreas: "…" })>` will result in different styles resolution before and after this version. This applies to `templateAreas`, `templateColumns`, and `templateRows`). From static analysis, we found only one known usage of this and it has been resolved.
16
+
3
17
  ## 1.20.0
4
18
 
5
19
  ### Minor Changes
@@ -1,15 +1,20 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.default = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
7
9
  var _react = require("react");
8
10
  var _react2 = require("@emotion/react");
9
11
  var _styleMaps = require("../xcss/style-maps.partial");
10
12
  var _xcss = require("../xcss/xcss");
11
13
  /** @jsx jsx */
12
14
 
15
+ var gridTemplateAreasVar = '--ds-grid--grid-template-areas';
16
+ var gridTemplateColumnsVar = '--ds-grid--grid-template-columns';
17
+ var gridTemplateRowsVar = '--ds-grid--grid-template-rows';
13
18
  var justifyContentMap = {
14
19
  start: (0, _react2.css)({
15
20
  justifyContent: 'start'
@@ -86,7 +91,10 @@ var alignItemsMap = {
86
91
  };
87
92
  var baseStyles = (0, _react2.css)({
88
93
  display: 'grid',
89
- boxSizing: 'border-box'
94
+ boxSizing: 'border-box',
95
+ gridTemplateAreas: "var(".concat(gridTemplateAreasVar, ")"),
96
+ gridTemplateColumns: "var(".concat(gridTemplateColumnsVar, ")"),
97
+ gridTemplateRows: "var(".concat(gridTemplateRowsVar, ")")
90
98
  });
91
99
  var gridAutoFlowMap = {
92
100
  row: (0, _react2.css)({
@@ -145,20 +153,28 @@ var Grid = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef)(fu
145
153
  xcss = _ref.xcss;
146
154
  var Component = as || 'div';
147
155
  var xcssClassName = xcss && (0, _xcss.parseXcss)(xcss);
148
- var style = gridTemplateAreas || gridTemplateColumns || gridTemplateRows ? Object.assign({}, {
149
- gridTemplateAreas: gridTemplateAreas ? gridTemplateAreas.map(function (str) {
156
+
157
+ /**
158
+ * We use CSS variables to allow for dynamic grid templates instead of dynamically setting to `props.style`
159
+ * This allows `props.xcss` to override them as `style={{ gridTemplateAreas }}` would have higher specificity.
160
+ *
161
+ * This must be reset to `initial` if `gridTemplateAreas` is not set, otherwise nested grids will break!
162
+ *
163
+ * NOTE: If we disallow `grid-template-areas` (etc) to be set via `props.xcss`, we can remove this.
164
+ */
165
+ var style = (0, _react.useMemo)(function () {
166
+ var _ref2;
167
+ return _ref2 = {}, (0, _defineProperty2.default)(_ref2, gridTemplateAreasVar, gridTemplateAreas ? gridTemplateAreas.map(function (str) {
150
168
  return "\"".concat(str, "\"");
151
- }).join('\n') : undefined,
152
- gridTemplateColumns: gridTemplateColumns,
153
- gridTemplateRows: gridTemplateRows
154
- }) : undefined;
169
+ }).join('\n') || 'initial' : 'initial'), (0, _defineProperty2.default)(_ref2, gridTemplateColumnsVar, gridTemplateColumns || 'initial'), (0, _defineProperty2.default)(_ref2, gridTemplateRowsVar, gridTemplateRows || 'initial'), _ref2;
170
+ }, [gridTemplateAreas, gridTemplateColumns, gridTemplateRows]);
155
171
  return (0, _react2.jsx)(Component, {
156
172
  id: id,
157
173
  role: role,
158
174
  style: style,
159
175
  css: [baseStyles, gap && _styleMaps.spaceStylesMap.gap[gap], columnGap && _styleMaps.spaceStylesMap.columnGap[columnGap], rowGap && _styleMaps.spaceStylesMap.rowGap[rowGap], alignItems && alignItemsMap[alignItems], alignContent && alignContentMap[alignContent], justifyContent && justifyContentMap[justifyContent], autoFlow && gridAutoFlowMap[autoFlow],
160
176
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
161
- xcssClassName && xcssClassName],
177
+ xcssClassName],
162
178
  "data-testid": testId,
163
179
  ref: ref
164
180
  }, children);
@@ -1,8 +1,11 @@
1
1
  /** @jsx jsx */
2
- import { forwardRef, memo } from 'react';
2
+ import { forwardRef, memo, useMemo } from 'react';
3
3
  import { css, jsx } from '@emotion/react';
4
4
  import { spaceStylesMap } from '../xcss/style-maps.partial';
5
5
  import { parseXcss } from '../xcss/xcss';
6
+ const gridTemplateAreasVar = '--ds-grid--grid-template-areas';
7
+ const gridTemplateColumnsVar = '--ds-grid--grid-template-columns';
8
+ const gridTemplateRowsVar = '--ds-grid--grid-template-rows';
6
9
  const justifyContentMap = {
7
10
  start: css({
8
11
  justifyContent: 'start'
@@ -79,7 +82,10 @@ const alignItemsMap = {
79
82
  };
80
83
  const baseStyles = css({
81
84
  display: 'grid',
82
- boxSizing: 'border-box'
85
+ boxSizing: 'border-box',
86
+ gridTemplateAreas: `var(${gridTemplateAreasVar})`,
87
+ gridTemplateColumns: `var(${gridTemplateColumnsVar})`,
88
+ gridTemplateRows: `var(${gridTemplateRowsVar})`
83
89
  });
84
90
  const gridAutoFlowMap = {
85
91
  row: css({
@@ -139,18 +145,27 @@ const Grid = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
139
145
  }, ref) => {
140
146
  const Component = as || 'div';
141
147
  const xcssClassName = xcss && parseXcss(xcss);
142
- const style = gridTemplateAreas || gridTemplateColumns || gridTemplateRows ? Object.assign({}, {
143
- gridTemplateAreas: gridTemplateAreas ? gridTemplateAreas.map(str => `"${str}"`).join('\n') : undefined,
144
- gridTemplateColumns,
145
- gridTemplateRows
146
- }) : undefined;
148
+
149
+ /**
150
+ * We use CSS variables to allow for dynamic grid templates instead of dynamically setting to `props.style`
151
+ * This allows `props.xcss` to override them as `style={{ gridTemplateAreas }}` would have higher specificity.
152
+ *
153
+ * This must be reset to `initial` if `gridTemplateAreas` is not set, otherwise nested grids will break!
154
+ *
155
+ * NOTE: If we disallow `grid-template-areas` (etc) to be set via `props.xcss`, we can remove this.
156
+ */
157
+ const style = useMemo(() => ({
158
+ [gridTemplateAreasVar]: gridTemplateAreas ? gridTemplateAreas.map(str => `"${str}"`).join('\n') || 'initial' : 'initial',
159
+ [gridTemplateColumnsVar]: gridTemplateColumns || 'initial',
160
+ [gridTemplateRowsVar]: gridTemplateRows || 'initial'
161
+ }), [gridTemplateAreas, gridTemplateColumns, gridTemplateRows]);
147
162
  return jsx(Component, {
148
163
  id: id,
149
164
  role: role,
150
165
  style: style,
151
166
  css: [baseStyles, gap && spaceStylesMap.gap[gap], columnGap && spaceStylesMap.columnGap[columnGap], rowGap && spaceStylesMap.rowGap[rowGap], alignItems && alignItemsMap[alignItems], alignContent && alignContentMap[alignContent], justifyContent && justifyContentMap[justifyContent], autoFlow && gridAutoFlowMap[autoFlow],
152
167
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
153
- xcssClassName && xcssClassName],
168
+ xcssClassName],
154
169
  "data-testid": testId,
155
170
  ref: ref
156
171
  }, children);
@@ -1,8 +1,12 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
1
2
  /** @jsx jsx */
2
- import { forwardRef, memo } from 'react';
3
+ import { forwardRef, memo, useMemo } from 'react';
3
4
  import { css, jsx } from '@emotion/react';
4
5
  import { spaceStylesMap } from '../xcss/style-maps.partial';
5
6
  import { parseXcss } from '../xcss/xcss';
7
+ var gridTemplateAreasVar = '--ds-grid--grid-template-areas';
8
+ var gridTemplateColumnsVar = '--ds-grid--grid-template-columns';
9
+ var gridTemplateRowsVar = '--ds-grid--grid-template-rows';
6
10
  var justifyContentMap = {
7
11
  start: css({
8
12
  justifyContent: 'start'
@@ -79,7 +83,10 @@ var alignItemsMap = {
79
83
  };
80
84
  var baseStyles = css({
81
85
  display: 'grid',
82
- boxSizing: 'border-box'
86
+ boxSizing: 'border-box',
87
+ gridTemplateAreas: "var(".concat(gridTemplateAreasVar, ")"),
88
+ gridTemplateColumns: "var(".concat(gridTemplateColumnsVar, ")"),
89
+ gridTemplateRows: "var(".concat(gridTemplateRowsVar, ")")
83
90
  });
84
91
  var gridAutoFlowMap = {
85
92
  row: css({
@@ -138,20 +145,28 @@ var Grid = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref, ref) {
138
145
  xcss = _ref.xcss;
139
146
  var Component = as || 'div';
140
147
  var xcssClassName = xcss && parseXcss(xcss);
141
- var style = gridTemplateAreas || gridTemplateColumns || gridTemplateRows ? Object.assign({}, {
142
- gridTemplateAreas: gridTemplateAreas ? gridTemplateAreas.map(function (str) {
148
+
149
+ /**
150
+ * We use CSS variables to allow for dynamic grid templates instead of dynamically setting to `props.style`
151
+ * This allows `props.xcss` to override them as `style={{ gridTemplateAreas }}` would have higher specificity.
152
+ *
153
+ * This must be reset to `initial` if `gridTemplateAreas` is not set, otherwise nested grids will break!
154
+ *
155
+ * NOTE: If we disallow `grid-template-areas` (etc) to be set via `props.xcss`, we can remove this.
156
+ */
157
+ var style = useMemo(function () {
158
+ var _ref2;
159
+ return _ref2 = {}, _defineProperty(_ref2, gridTemplateAreasVar, gridTemplateAreas ? gridTemplateAreas.map(function (str) {
143
160
  return "\"".concat(str, "\"");
144
- }).join('\n') : undefined,
145
- gridTemplateColumns: gridTemplateColumns,
146
- gridTemplateRows: gridTemplateRows
147
- }) : undefined;
161
+ }).join('\n') || 'initial' : 'initial'), _defineProperty(_ref2, gridTemplateColumnsVar, gridTemplateColumns || 'initial'), _defineProperty(_ref2, gridTemplateRowsVar, gridTemplateRows || 'initial'), _ref2;
162
+ }, [gridTemplateAreas, gridTemplateColumns, gridTemplateRows]);
148
163
  return jsx(Component, {
149
164
  id: id,
150
165
  role: role,
151
166
  style: style,
152
167
  css: [baseStyles, gap && spaceStylesMap.gap[gap], columnGap && spaceStylesMap.columnGap[columnGap], rowGap && spaceStylesMap.rowGap[rowGap], alignItems && alignItemsMap[alignItems], alignContent && alignContentMap[alignContent], justifyContent && justifyContentMap[justifyContent], autoFlow && gridAutoFlowMap[autoFlow],
153
168
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
154
- xcssClassName && xcssClassName],
169
+ xcssClassName],
155
170
  "data-testid": testId,
156
171
  ref: ref
157
172
  }, children);
@@ -1,5 +1,5 @@
1
1
  /** @jsx jsx */
2
- import { ElementType, ReactNode } from 'react';
2
+ import { type ElementType, type ReactNode } from 'react';
3
3
  import { type Space } from '../xcss/style-maps.partial';
4
4
  import type { BasePrimitiveProps } from './types';
5
5
  export type GridProps<T extends ElementType = 'div'> = {
@@ -58,11 +58,11 @@ export type GridProps<T extends ElementType = 'div'> = {
58
58
  */
59
59
  children: ReactNode;
60
60
  /**
61
- * HTML id attrubute
61
+ * HTML id attrubute.
62
62
  */
63
63
  id?: string;
64
64
  /**
65
- * Forwarded ref element
65
+ * Forwarded ref element.
66
66
  */
67
67
  ref?: React.ComponentPropsWithRef<T>['ref'];
68
68
  } & BasePrimitiveProps;
@@ -184,11 +184,11 @@ declare const Grid: import("react").MemoExoticComponent<import("react").ForwardR
184
184
  */
185
185
  children: ReactNode;
186
186
  /**
187
- * HTML id attrubute
187
+ * HTML id attrubute.
188
188
  */
189
189
  id?: string | undefined;
190
190
  /**
191
- * Forwarded ref element
191
+ * Forwarded ref element.
192
192
  */
193
193
  ref?: any;
194
194
  } & BasePrimitiveProps, "gap" | "rowGap" | "columnGap" | "alignContent" | "alignItems" | "justifyContent" | "justifyItems" | "children" | "as" | "id" | keyof BasePrimitiveProps | "autoFlow" | "templateAreas" | "templateRows" | "templateColumns"> & import("react").RefAttributes<any>>>;
@@ -1,5 +1,5 @@
1
1
  /** @jsx jsx */
2
- import { ElementType, ReactNode } from 'react';
2
+ import { type ElementType, type ReactNode } from 'react';
3
3
  import { type Space } from '../xcss/style-maps.partial';
4
4
  import type { BasePrimitiveProps } from './types';
5
5
  export type GridProps<T extends ElementType = 'div'> = {
@@ -58,11 +58,11 @@ export type GridProps<T extends ElementType = 'div'> = {
58
58
  */
59
59
  children: ReactNode;
60
60
  /**
61
- * HTML id attrubute
61
+ * HTML id attrubute.
62
62
  */
63
63
  id?: string;
64
64
  /**
65
- * Forwarded ref element
65
+ * Forwarded ref element.
66
66
  */
67
67
  ref?: React.ComponentPropsWithRef<T>['ref'];
68
68
  } & BasePrimitiveProps;
@@ -184,11 +184,11 @@ declare const Grid: import("react").MemoExoticComponent<import("react").ForwardR
184
184
  */
185
185
  children: ReactNode;
186
186
  /**
187
- * HTML id attrubute
187
+ * HTML id attrubute.
188
188
  */
189
189
  id?: string | undefined;
190
190
  /**
191
- * Forwarded ref element
191
+ * Forwarded ref element.
192
192
  */
193
193
  ref?: any;
194
194
  } & BasePrimitiveProps, "gap" | "rowGap" | "columnGap" | "alignContent" | "alignItems" | "justifyContent" | "justifyItems" | "children" | "as" | "id" | keyof BasePrimitiveProps | "autoFlow" | "templateAreas" | "templateRows" | "templateColumns"> & import("react").RefAttributes<any>>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/primitives",
3
- "version": "1.20.0",
3
+ "version": "2.0.1",
4
4
  "description": "Primitives are token-backed low-level building blocks.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -104,7 +104,7 @@
104
104
  "codegen-styles": "ts-node -r tsconfig-paths/register ./scripts/codegen-styles.tsx"
105
105
  },
106
106
  "dependencies": {
107
- "@atlaskit/app-provider": "^0.4.0",
107
+ "@atlaskit/app-provider": "^1.0.0",
108
108
  "@atlaskit/tokens": "^1.35.0",
109
109
  "@babel/runtime": "^7.0.0",
110
110
  "@emotion/react": "^11.7.1",