@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,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 { SerializedStyles } 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<SerializedStyles>;
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.1",
4
4
  "description": "Primitives are token-backed low-level building blocks.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,10 +34,10 @@
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
- "@atlaskit/ds-explorations": "*",
41
41
  "@atlaskit/tokens": "^1.2.0",
42
42
  "@babel/runtime": "^7.0.0",
43
43
  "@emotion/react": "^11.7.1",
package/report.api.md CHANGED
@@ -26,7 +26,6 @@ import { ReactElement } from 'react';
26
26
  import { ReactNode } from 'react';
27
27
  import { RefAttributes } from 'react';
28
28
  import { SerializedStyles } from '@emotion/react';
29
- import { UNSAFE_Breakpoint } from '@atlaskit/ds-explorations';
30
29
 
31
30
  // @public (undocumented)
32
31
  type AlignBlock = 'baseline' | 'center' | 'end' | 'start';
@@ -138,7 +137,7 @@ type BaseBoxPropsFoundation<T extends ElementType> = {
138
137
  backgroundColor?: BackgroundColor;
139
138
  shadow?: Shadow;
140
139
  borderStyle?: BorderStyle;
141
- borderWidth?: BorderWidth | Partial<Record<UNSAFE_Breakpoint, BorderWidth>>;
140
+ borderWidth?: BorderWidth | ResponsiveObject<BorderWidth>;
142
141
  borderColor?: BorderColor;
143
142
  borderRadius?: BorderRadius;
144
143
  layer?: Layer;
@@ -149,28 +148,18 @@ type BaseBoxPropsFoundation<T extends ElementType> = {
149
148
  overflow?: Overflow;
150
149
  overflowInline?: OverflowInline;
151
150
  overflowBlock?: OverflowBlock;
152
- padding?: Padding | Partial<Record<UNSAFE_Breakpoint, Padding>>;
153
- paddingBlock?:
154
- | PaddingBlock
155
- | Partial<Record<UNSAFE_Breakpoint, PaddingBlock>>;
156
- paddingBlockStart?:
157
- | PaddingBlockStart
158
- | Partial<Record<UNSAFE_Breakpoint, PaddingBlockStart>>;
159
- paddingBlockEnd?:
160
- | PaddingBlockEnd
161
- | Partial<Record<UNSAFE_Breakpoint, PaddingBlockEnd>>;
162
- paddingInline?:
163
- | PaddingInline
164
- | Partial<Record<UNSAFE_Breakpoint, PaddingInline>>;
151
+ padding?: Padding | ResponsiveObject<Padding>;
152
+ paddingBlock?: PaddingBlock | ResponsiveObject<PaddingBlock>;
153
+ paddingBlockStart?: PaddingBlockStart | ResponsiveObject<PaddingBlockStart>;
154
+ paddingBlockEnd?: PaddingBlockEnd | ResponsiveObject<PaddingBlockEnd>;
155
+ paddingInline?: PaddingInline | ResponsiveObject<PaddingInline>;
165
156
  paddingInlineStart?:
166
157
  | PaddingInlineStart
167
- | Partial<Record<UNSAFE_Breakpoint, PaddingInlineStart>>;
168
- paddingInlineEnd?:
169
- | PaddingInlineEnd
170
- | Partial<Record<UNSAFE_Breakpoint, PaddingInlineEnd>>;
158
+ | ResponsiveObject<PaddingInlineStart>;
159
+ paddingInlineEnd?: PaddingInlineEnd | ResponsiveObject<PaddingInlineEnd>;
171
160
  width?: Width;
172
161
  height?: Height;
173
- display?: Display | Partial<Record<UNSAFE_Breakpoint, Display>>;
162
+ display?: Display | ResponsiveObject<Display>;
174
163
  position?: Position;
175
164
  ref?: ComponentPropsWithRef<T>['ref'];
176
165
  };
@@ -275,6 +264,9 @@ export type BoxProps<T extends ElementType = 'div'> = Omit<
275
264
  // @public (undocumented)
276
265
  type BoxResponsiveProp = typeof BOX_RESPONSIVE_PROPS[number];
277
266
 
267
+ // @public
268
+ type Breakpoint = 'lg' | 'md' | 'sm' | 'xl' | 'xs' | 'xxl' | 'xxs';
269
+
278
270
  // @public
279
271
  type CustomStyles = Pick<
280
272
  CSSProperties,
@@ -487,6 +479,9 @@ type PublicBoxPropsBase = {
487
479
  customStyles?: CustomStyles;
488
480
  };
489
481
 
482
+ // @public
483
+ type ResponsiveObject<T> = Partial<Record<Breakpoint, T>>;
484
+
490
485
  // @public (undocumented)
491
486
  type Shadow = keyof typeof shadowMap;
492
487
 
@@ -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
+ }
@@ -15,7 +15,6 @@ import { ReactElement } from 'react';
15
15
  import { ReactNode } from 'react';
16
16
  import { RefAttributes } from 'react';
17
17
  import { SerializedStyles } from '@emotion/react';
18
- import { UNSAFE_Breakpoint } from '@atlaskit/ds-explorations';
19
18
 
20
19
  // @public (undocumented)
21
20
  type AlignBlock = 'baseline' | 'center' | 'end' | 'start';
@@ -122,7 +121,7 @@ type BaseBoxPropsFoundation<T extends ElementType> = {
122
121
  backgroundColor?: BackgroundColor;
123
122
  shadow?: Shadow;
124
123
  borderStyle?: BorderStyle;
125
- borderWidth?: BorderWidth | Partial<Record<UNSAFE_Breakpoint, BorderWidth>>;
124
+ borderWidth?: BorderWidth | ResponsiveObject<BorderWidth>;
126
125
  borderColor?: BorderColor;
127
126
  borderRadius?: BorderRadius;
128
127
  layer?: Layer;
@@ -133,16 +132,16 @@ type BaseBoxPropsFoundation<T extends ElementType> = {
133
132
  overflow?: Overflow;
134
133
  overflowInline?: OverflowInline;
135
134
  overflowBlock?: OverflowBlock;
136
- padding?: Padding | Partial<Record<UNSAFE_Breakpoint, Padding>>;
137
- paddingBlock?: PaddingBlock | Partial<Record<UNSAFE_Breakpoint, PaddingBlock>>;
138
- paddingBlockStart?: PaddingBlockStart | Partial<Record<UNSAFE_Breakpoint, PaddingBlockStart>>;
139
- paddingBlockEnd?: PaddingBlockEnd | Partial<Record<UNSAFE_Breakpoint, PaddingBlockEnd>>;
140
- paddingInline?: PaddingInline | Partial<Record<UNSAFE_Breakpoint, PaddingInline>>;
141
- paddingInlineStart?: PaddingInlineStart | Partial<Record<UNSAFE_Breakpoint, PaddingInlineStart>>;
142
- paddingInlineEnd?: PaddingInlineEnd | Partial<Record<UNSAFE_Breakpoint, PaddingInlineEnd>>;
135
+ padding?: Padding | ResponsiveObject<Padding>;
136
+ paddingBlock?: PaddingBlock | ResponsiveObject<PaddingBlock>;
137
+ paddingBlockStart?: PaddingBlockStart | ResponsiveObject<PaddingBlockStart>;
138
+ paddingBlockEnd?: PaddingBlockEnd | ResponsiveObject<PaddingBlockEnd>;
139
+ paddingInline?: PaddingInline | ResponsiveObject<PaddingInline>;
140
+ paddingInlineStart?: PaddingInlineStart | ResponsiveObject<PaddingInlineStart>;
141
+ paddingInlineEnd?: PaddingInlineEnd | ResponsiveObject<PaddingInlineEnd>;
143
142
  width?: Width;
144
143
  height?: Height;
145
- display?: Display | Partial<Record<UNSAFE_Breakpoint, Display>>;
144
+ display?: Display | ResponsiveObject<Display>;
146
145
  position?: Position;
147
146
  ref?: ComponentPropsWithRef<T>['ref'];
148
147
  };
@@ -228,6 +227,9 @@ export type BoxProps<T extends ElementType = 'div'> = Omit<BaseBoxProps<T>, 'UNS
228
227
  // @public (undocumented)
229
228
  type BoxResponsiveProp = typeof BOX_RESPONSIVE_PROPS[number];
230
229
 
230
+ // @public
231
+ type Breakpoint = 'lg' | 'md' | 'sm' | 'xl' | 'xs' | 'xxl' | 'xxs';
232
+
231
233
  // @public
232
234
  type CustomStyles = Pick<CSSProperties, 'flex' | 'flexBasis' | 'float' | 'height' | 'insetBlockStart' | 'insetInlineEnd' | 'insetInlineStart' | 'margin' | 'marginBlock' | 'marginBlockEnd' | 'marginBlockStart' | 'marginInline' | 'marginInlineEnd' | 'marginInlineStart' | 'maxHeight' | 'maxWidth' | 'minHeight' | 'minWidth' | 'paddingBottom' | 'paddingLeft' | 'paddingRight' | 'paddingTop' | 'width'>;
233
235
 
@@ -413,6 +415,9 @@ type PublicBoxPropsBase = {
413
415
  customStyles?: CustomStyles;
414
416
  };
415
417
 
418
+ // @public
419
+ type ResponsiveObject<T> = Partial<Record<Breakpoint, T>>;
420
+
416
421
  // @public (undocumented)
417
422
  type Shadow = keyof typeof shadowMap;
418
423