@atlaskit/primitives 1.4.3 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/constellation/heading/code.mdx +19 -0
  3. package/constellation/heading/examples.mdx +28 -0
  4. package/constellation/heading/usage.mdx +21 -0
  5. package/constellation/responsive/usage.mdx +1 -1
  6. package/dist/cjs/components/box.js +1 -1
  7. package/dist/cjs/components/heading-context.js +44 -0
  8. package/dist/cjs/components/heading.js +95 -0
  9. package/dist/cjs/components/internal/surface-provider.js +27 -0
  10. package/dist/cjs/components/text.js +131 -0
  11. package/dist/cjs/xcss/style-maps.partial.js +114 -6
  12. package/dist/es2019/components/box.js +2 -2
  13. package/dist/es2019/components/heading-context.js +35 -0
  14. package/dist/es2019/components/heading.js +87 -0
  15. package/dist/es2019/components/internal/surface-provider.js +19 -0
  16. package/dist/es2019/components/text.js +127 -0
  17. package/dist/es2019/xcss/style-maps.partial.js +92 -4
  18. package/dist/esm/components/box.js +2 -2
  19. package/dist/esm/components/heading-context.js +34 -0
  20. package/dist/esm/components/heading.js +87 -0
  21. package/dist/esm/components/internal/surface-provider.js +19 -0
  22. package/dist/esm/components/text.js +128 -0
  23. package/dist/esm/xcss/style-maps.partial.js +94 -4
  24. package/dist/types/components/heading-context.d.ts +31 -0
  25. package/dist/types/components/heading.d.ts +45 -0
  26. package/dist/types/components/internal/surface-provider.d.ts +15 -0
  27. package/dist/types/components/text.d.ts +57 -0
  28. package/dist/types/xcss/style-maps.partial.d.ts +114 -2
  29. package/dist/types-ts4.5/components/heading-context.d.ts +31 -0
  30. package/dist/types-ts4.5/components/heading.d.ts +45 -0
  31. package/dist/types-ts4.5/components/internal/surface-provider.d.ts +15 -0
  32. package/dist/types-ts4.5/components/text.d.ts +63 -0
  33. package/dist/types-ts4.5/xcss/style-maps.partial.d.ts +114 -2
  34. package/extract-react-types/box-props.tsx +3 -1
  35. package/extract-react-types/heading-props.tsx +3 -0
  36. package/heading/package.json +15 -0
  37. package/heading-context/package.json +15 -0
  38. package/package.json +17 -4
  39. package/report.api.md +1 -0
  40. package/scripts/__tests__/__snapshots__/codegen.test.tsx.snap +34 -0
  41. package/scripts/__tests__/codegen.test.tsx +4 -0
  42. package/scripts/codegen-styles.tsx +12 -0
  43. package/scripts/color-codegen-template.tsx +9 -0
  44. package/scripts/typography-codegen-template.tsx +107 -0
  45. package/tmp/api-report-tmp.d.ts +1 -0
@@ -0,0 +1,87 @@
1
+ /** @jsx jsx */
2
+ import { css, jsx } from '@emotion/react';
3
+ import { useHeadingElement } from './heading-context';
4
+ // https://atlassian.design/foundations/typography
5
+ const levelMap = {
6
+ xxl: 'h1',
7
+ xl: 'h2',
8
+ lg: 'h3',
9
+ md: 'h4',
10
+ sm: 'h5',
11
+ xs: 'h6',
12
+ xxs: 'div'
13
+ };
14
+ const headingResetStyles = css({
15
+ color: "var(--ds-text, #172B4D)",
16
+ letterSpacing: 'normal',
17
+ marginBlock: 0,
18
+ textTransform: 'none'
19
+ });
20
+ const headingStylesMap = {
21
+ xxl: css({
22
+ font: "var(--ds-font-heading-xxl, inherit)"
23
+ }),
24
+ xl: css({
25
+ font: "var(--ds-font-heading-xl, inherit)"
26
+ }),
27
+ lg: css({
28
+ font: "var(--ds-font-heading-lg, inherit)"
29
+ }),
30
+ md: css({
31
+ font: "var(--ds-font-heading-md, inherit)"
32
+ }),
33
+ sm: css({
34
+ font: "var(--ds-font-heading-sm, inherit)"
35
+ }),
36
+ xs: css({
37
+ font: "var(--ds-font-heading-xs, inherit)"
38
+ }),
39
+ xxs: css({
40
+ font: "var(--ds-font-heading-xxs, inherit)"
41
+ })
42
+ };
43
+ const inverseStyles = css({
44
+ color: "var(--ds-text-inverse, #FFF)"
45
+ });
46
+ /**
47
+ * __Heading__
48
+ *
49
+ * A heading is a typography component used to display text in different sizes and formats.
50
+ *
51
+ * @example
52
+ *
53
+ * ```jsx
54
+ * import Heading from '@atlaskit/heading';
55
+ *
56
+ * const HeadingXXL = () => (
57
+ * <Heading level="xxl">XXL</Heading>
58
+ * );
59
+ * ```
60
+ */
61
+ const Heading = ({
62
+ children,
63
+ level,
64
+ id,
65
+ testId,
66
+ as,
67
+ color = 'default'
68
+ }) => {
69
+ if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'production' && as && typeof as !== 'string') {
70
+ throw new Error('`as` prop should be a string.');
71
+ }
72
+ const hLevel = useHeadingElement();
73
+ /**
74
+ * Order here is important, we for now apply
75
+ * 1. user choice
76
+ * 2. inferred a11y level
77
+ * 3. default final fallback
78
+ */
79
+ const Markup = as || hLevel && (hLevel > 6 ? 'div' : `h${hLevel}`) || levelMap[level];
80
+ return jsx(Markup, {
81
+ id: id,
82
+ "data-testid": testId,
83
+ role: Markup === 'div' ? 'heading' : undefined,
84
+ css: [headingResetStyles, level && headingStylesMap[level], color === 'inverse' && inverseStyles]
85
+ }, children);
86
+ };
87
+ export default Heading;
@@ -0,0 +1,19 @@
1
+ import { createContext, useContext } from 'react';
2
+ /**
3
+ * __Surface context__
4
+ *
5
+ * A surface context provides context information on the current background (if set).
6
+ */
7
+ export const SurfaceContext = /*#__PURE__*/createContext('elevation.surface');
8
+
9
+ /**
10
+ * __useSurface__
11
+ *
12
+ * Return the current surface. If no parent sets a surface color it falls back to the default surface.
13
+ *
14
+ * @see SurfaceContext
15
+ */
16
+ export const useSurface = () => {
17
+ return useContext(SurfaceContext);
18
+ };
19
+ SurfaceContext.displayName = 'SurfaceProvider';
@@ -0,0 +1,127 @@
1
+ /** @jsx jsx */
2
+ import { createContext, Fragment, useContext } from 'react';
3
+ import { css, jsx } from '@emotion/react';
4
+ import invariant from 'tiny-invariant';
5
+ import { bodyTextStylesMap
6
+
7
+ // textColorStylesMap,
8
+ , uiTextStylesMap } from '../xcss/style-maps.partial';
9
+
10
+ // import surfaceColorMap from '../internal/color-map';
11
+
12
+ // import { useSurface } from './internal/surface-provider';
13
+ const asAllowlist = ['span', 'p', 'strong', 'em', 'label'];
14
+ const variantStyles = {
15
+ ...bodyTextStylesMap,
16
+ ...uiTextStylesMap
17
+ };
18
+ const textAlignMap = {
19
+ center: css({
20
+ textAlign: 'center'
21
+ }),
22
+ end: css({
23
+ textAlign: 'end'
24
+ }),
25
+ start: css({
26
+ textAlign: 'start'
27
+ })
28
+ };
29
+
30
+ // p tag has padding on top in css-reset. dont know if we want to add it here
31
+ const baseStyles = css({
32
+ margin: "var(--ds-space-0, 0px)",
33
+ padding: "var(--ds-space-0, 0px)"
34
+ });
35
+ const truncateStyles = css({
36
+ overflow: 'hidden',
37
+ textOverflow: 'ellipsis',
38
+ whiteSpace: 'nowrap'
39
+ });
40
+
41
+ // TODO
42
+ // const asElementStyles: Record<AsElement, SerializedStyles> = {
43
+ // abbr: css({
44
+ // borderBottom: `1px ${token('color.border', '#ccc')} dotted`,
45
+ // cursor: 'help',
46
+ // }),
47
+ // };
48
+
49
+ /**
50
+ * Custom hook designed to abstract the parsing of the color props and make it clearer in the future how color is reconciled between themes and tokens.
51
+ */
52
+ // const useColor = (colorProp: TextColor): NonNullable<TextColor> => {
53
+ // const surface = useSurface();
54
+ // const inverseTextColor =
55
+ // surfaceColorMap[surface as keyof typeof surfaceColorMap];
56
+
57
+ // /**
58
+ // * Where the color of the surface is inverted we override the user choice
59
+ // * as there is no valid choice that is not covered by the override.
60
+ // */
61
+ // const color = inverseTextColor ?? colorProp;
62
+
63
+ // return color;
64
+ // };
65
+
66
+ const HasTextAncestorContext = /*#__PURE__*/createContext(false);
67
+ const useHasTextAncestor = () => useContext(HasTextAncestorContext);
68
+
69
+ /**
70
+ * __Text__
71
+ *
72
+ * Text is a primitive component that has the Atlassian Design System's design guidelines baked in.
73
+ * This includes considerations for text attributes such as color, font size, font weight, and line height.
74
+ * It renders a `span` by default.
75
+ *
76
+ * @internal
77
+ */
78
+ const Text = ({
79
+ children,
80
+ ...props
81
+ }) => {
82
+ const {
83
+ as: asElement,
84
+ // color: colorProp,
85
+ shouldTruncate = false,
86
+ textAlign,
87
+ testId,
88
+ id,
89
+ variant
90
+ } = props;
91
+ let Component = asElement;
92
+ if (!Component) {
93
+ if (variant.includes('body')) {
94
+ Component = 'p';
95
+ } else {
96
+ // ui text and default => span
97
+ Component = 'span';
98
+ }
99
+ }
100
+ invariant(asAllowlist.includes(Component), `@atlaskit/ds-explorations: Text received an invalid "as" value of "${Component}"`);
101
+ // const color = useColor(colorProp!);
102
+ const isWrapped = useHasTextAncestor();
103
+
104
+ /**
105
+ * If the text is already wrapped and applies no props we can just
106
+ * render the children directly as a fragment.
107
+ */
108
+ if (isWrapped && Object.keys(props).length === 0) {
109
+ return jsx(Fragment, null, children);
110
+ }
111
+ const component = jsx(Component
112
+ // style={UNSAFE_style}
113
+ , {
114
+ css: [baseStyles, variant && variantStyles[variant],
115
+ // color && textColorMap[color],
116
+ // colorProp && textColorMap[colorProp],
117
+ shouldTruncate && truncateStyles, textAlign && textAlignMap[textAlign]],
118
+ "data-testid": testId,
119
+ id: id
120
+ }, children);
121
+ return isWrapped ?
122
+ // no need to re-apply context if the text is already wrapped
123
+ component : jsx(HasTextAncestorContext.Provider, {
124
+ value: true
125
+ }, component);
126
+ };
127
+ export default Text;
@@ -1,4 +1,6 @@
1
1
  import { css } from '@emotion/react';
2
+ import { CURRENT_SURFACE_CSS_VAR } from '@atlaskit/tokens';
3
+
2
4
  /**
3
5
  * THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
4
6
  * @codegen <<SignedSource::7af6097e56f7fb03635b6f8aaf121b02>>
@@ -48,10 +50,10 @@ export const spaceMap = {
48
50
  */
49
51
  /**
50
52
  * THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
51
- * @codegen <<SignedSource::3f4d926ce14cda107d25c697f3a0c200>>
53
+ * @codegen <<SignedSource::3db44f53b728773bb3ba1473d4567724>>
52
54
  * @codegenId colors
53
55
  * @codegenCommand yarn workspace @atlaskit/primitives codegen-styles
54
- * @codegenParams ["border", "background", "shadow", "text", "fill"]
56
+ * @codegenParams ["border", "background", "shadow", "text", "fill", "surface"]
55
57
  * @codegenDependency ../../../tokens/src/artifacts/tokens-raw/atlassian-light.tsx <<SignedSource::815ddd719715ae06521cad06e1921e40>>
56
58
  */
57
59
  export const borderColorMap = {
@@ -273,7 +275,8 @@ export const backgroundColorMap = {
273
275
  'elevation.surface.raised': "var(--ds-surface-raised, #FFFFFF)",
274
276
  'elevation.surface.raised.hovered': "var(--ds-surface-raised-hovered, #FAFBFC)",
275
277
  'elevation.surface.raised.pressed': "var(--ds-surface-raised-pressed, #F4F5F7)",
276
- 'elevation.surface.sunken': "var(--ds-surface-sunken, #F4F5F7)"
278
+ 'elevation.surface.sunken': "var(--ds-surface-sunken, #F4F5F7)",
279
+ 'utility.elevation.surface.current': "var(--ds-elevation-surface-current, #FFFFFF)"
277
280
  };
278
281
  export const shadowMap = {
279
282
  'elevation.shadow.overflow': "var(--ds-shadow-overflow, 0px 0px 8px #091e423f, 0px 0px 1px #091e424f)",
@@ -343,6 +346,18 @@ export const fillMap = {
343
346
  'color.icon.information': "var(--ds-icon-information, #0747A6)",
344
347
  'color.icon.subtle': "var(--ds-icon-subtle, #6B778C)"
345
348
  };
349
+ export const surfaceColorMap = {
350
+ 'elevation.surface': "var(--ds-surface, #FFFFFF)",
351
+ 'elevation.surface.hovered': "var(--ds-surface-hovered, #FAFBFC)",
352
+ 'elevation.surface.pressed': "var(--ds-surface-pressed, #F4F5F7)",
353
+ 'elevation.surface.overlay': "var(--ds-surface-overlay, #FFFFFF)",
354
+ 'elevation.surface.overlay.hovered': "var(--ds-surface-overlay-hovered, #FAFBFC)",
355
+ 'elevation.surface.overlay.pressed': "var(--ds-surface-overlay-pressed, #F4F5F7)",
356
+ 'elevation.surface.raised': "var(--ds-surface-raised, #FFFFFF)",
357
+ 'elevation.surface.raised.hovered': "var(--ds-surface-raised-hovered, #FAFBFC)",
358
+ 'elevation.surface.raised.pressed': "var(--ds-surface-raised-pressed, #F4F5F7)",
359
+ 'elevation.surface.sunken': "var(--ds-surface-sunken, #F4F5F7)"
360
+ };
346
361
  /**
347
362
  * @codegenEnd
348
363
  */
@@ -392,6 +407,69 @@ export const borderRadiusMap = {
392
407
  'border.radius.400': "var(--ds-border-radius-400, 16px)",
393
408
  'border.radius.circle': "var(--ds-border-radius-circle, 32032px)"
394
409
  };
410
+ /**
411
+ * @codegenEnd
412
+ */
413
+ /**
414
+ * THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
415
+ * @codegen <<SignedSource::752c1b8bdc7db62e519dd729222d57ad>>
416
+ * @codegenId typography
417
+ * @codegenCommand yarn workspace @atlaskit/primitives codegen-styles
418
+ * @codegenParams ["fontSize", "fontWeight", "fontFamily", "lineHeight", "body", "heading", "ui"]
419
+ * @codegenDependency ../../scripts/codegen-file-templates/dimensions.tsx <<SignedSource::0cd422575c3f2a3784eeef767abe71f4>>
420
+ * @codegenDependency ../../scripts/codegen-file-templates/layer.tsx <<SignedSource::79d24a1e558f12d671c06a7609f90dc1>>
421
+ */
422
+ export const fontSizeMap = {
423
+ 'font.size.050': "var(--ds-font-size-050, 11px)",
424
+ 'font.size.075': "var(--ds-font-size-075, 12px)",
425
+ 'font.size.100': "var(--ds-font-size-100, 14px)",
426
+ 'font.size.200': "var(--ds-font-size-200, 16px)",
427
+ 'font.size.300': "var(--ds-font-size-300, 20px)",
428
+ 'font.size.400': "var(--ds-font-size-400, 24px)",
429
+ 'font.size.500': "var(--ds-font-size-500, 29px)",
430
+ 'font.size.600': "var(--ds-font-size-600, 35px)"
431
+ };
432
+ export const fontWeightMap = {
433
+ 'font.weight.bold': "var(--ds-font-weight-bold, 700)",
434
+ 'font.weight.medium': "var(--ds-font-weight-medium, 500)",
435
+ 'font.weight.regular': "var(--ds-font-weight-regular, 400)",
436
+ 'font.weight.semibold': "var(--ds-font-weight-semibold, 600)"
437
+ };
438
+ export const fontFamilyMap = {
439
+ 'font.family.body': "var(--ds-font-family-body, ui-sans-serif, \"Segoe UI\", system-ui, Ubuntu, \"Helvetica Neue\", sans-serif)",
440
+ 'font.family.brand': "var(--ds-font-family-brand, Charlie Sans)",
441
+ 'font.family.code': "var(--ds-font-family-code, ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)",
442
+ 'font.family.heading': "var(--ds-font-family-heading, ui-sans-serif, \"Segoe UI\", system-ui, Ubuntu, \"Helvetica Neue\", sans-serif)",
443
+ 'font.family.monospace': "var(--ds-font-family-monospace, ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)",
444
+ 'font.family.sans': "var(--ds-font-family-sans, -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Roboto\", \"Oxygen\", \"Ubuntu\", \"Fira Sans\", \"Droid Sans\", \"Helvetica Neue\", sans-serif)"
445
+ };
446
+ export const lineHeightMap = {
447
+ 'font.lineHeight.1': "var(--ds-font-lineHeight-1, 1)",
448
+ 'font.lineHeight.100': "var(--ds-font-lineHeight-100, 16px)",
449
+ 'font.lineHeight.200': "var(--ds-font-lineHeight-200, 20px)",
450
+ 'font.lineHeight.300': "var(--ds-font-lineHeight-300, 24px)",
451
+ 'font.lineHeight.400': "var(--ds-font-lineHeight-400, 28px)",
452
+ 'font.lineHeight.500': "var(--ds-font-lineHeight-500, 32px)",
453
+ 'font.lineHeight.600': "var(--ds-font-lineHeight-600, 40px)"
454
+ };
455
+ export const bodyTextMap = {
456
+ body: "var(--ds-font-body, normal 400 14px/20px var(--ds-font-family-body))",
457
+ 'body.lg': "var(--ds-font-body-lg, normal 400 16px/24px var(--ds-font-family-body))",
458
+ 'body.sm': "var(--ds-font-body-sm, normal 400 11px/20px var(--ds-font-family-body))"
459
+ };
460
+ export const headingTextMap = {
461
+ 'heading.lg': "var(--ds-font-heading-lg, normal 500 24px/28px var(--ds-font-family-heading))",
462
+ 'heading.md': "var(--ds-font-heading-md, normal 500 20px/24px var(--ds-font-family-heading))",
463
+ 'heading.sm': "var(--ds-font-heading-sm, normal 600 16px/20px var(--ds-font-family-heading))",
464
+ 'heading.xl': "var(--ds-font-heading-xl, normal 600 29px/32px var(--ds-font-family-heading))",
465
+ 'heading.xs': "var(--ds-font-heading-xs, normal 600 14px/16px var(--ds-font-family-heading))",
466
+ 'heading.xxl': "var(--ds-font-heading-xxl, normal 500 35px/40px var(--ds-font-family-heading))",
467
+ 'heading.xxs': "var(--ds-font-heading-xxs, normal 600 12px/16px var(--ds-font-family-heading))"
468
+ };
469
+ export const uiTextMap = {
470
+ ui: "var(--ds-font-ui, normal 400 14px/1 var(--ds-font-family-body))",
471
+ 'ui.sm': "var(--ds-font-ui-sm, normal 400 11px/1 var(--ds-font-family-body))"
472
+ };
395
473
 
396
474
  /**
397
475
  * @codegenEnd
@@ -419,4 +497,14 @@ export const spaceStylesMap = spacingProperties.reduce((styleMap, spacingPropert
419
497
  styleMap[spacingProperty] = getSerializedStylesMap(spacingProperty, spaceMap);
420
498
  return styleMap;
421
499
  }, {});
422
- export const backgroundColorStylesMap = getSerializedStylesMap('backgroundColor', backgroundColorMap);
500
+ export const backgroundColorStylesMap = getSerializedStylesMap('backgroundColor', backgroundColorMap);
501
+ export const textColorStylesMap = getSerializedStylesMap('color', textColorMap);
502
+ export const fontSizeStylesMap = getSerializedStylesMap('fontSize', fontSizeMap);
503
+ export const fontWeightStylesMap = getSerializedStylesMap('fontWeight', fontWeightMap);
504
+ export const fontFamilyStylesMap = getSerializedStylesMap('fontFamily', fontFamilyMap);
505
+ export const lineHeightStylesMap = getSerializedStylesMap('lineHeight', lineHeightMap);
506
+ export const headingTextStylesMap = getSerializedStylesMap('font', headingTextMap);
507
+ export const bodyTextStylesMap = getSerializedStylesMap('font', bodyTextMap);
508
+ export const uiTextStylesMap = getSerializedStylesMap('font', uiTextMap);
509
+ export const surfaceColorStylesMap = getSerializedStylesMap(CURRENT_SURFACE_CSS_VAR, surfaceColorMap);
510
+ export const isSurfaceColorToken = color => surfaceColorMap[color] !== undefined;
@@ -5,7 +5,7 @@ var _excluded = ["as", "children", "backgroundColor", "padding", "paddingBlock",
5
5
  /** @jsx jsx */
6
6
  import { forwardRef } from 'react';
7
7
  import { css, jsx } from '@emotion/react';
8
- import { backgroundColorStylesMap, paddingStylesMap } from '../xcss/style-maps.partial';
8
+ import { backgroundColorStylesMap, isSurfaceColorToken, paddingStylesMap, surfaceColorStylesMap } from '../xcss/style-maps.partial';
9
9
  import { parseXcss } from '../xcss/xcss';
10
10
 
11
11
  // Can either Exclude or Extract - here we're excluding all SVG-related elements
@@ -53,7 +53,7 @@ export var Box = /*#__PURE__*/forwardRef(function (_ref, ref) {
53
53
  ref: ref
54
54
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
55
55
  }, safeHtmlAttributes, {
56
- css: [baseStyles, backgroundColor && backgroundColorStylesMap[backgroundColor], padding && paddingStylesMap.padding[padding], paddingBlock && paddingStylesMap.paddingBlock[paddingBlock], paddingBlockStart && paddingStylesMap.paddingBlockStart[paddingBlockStart], paddingBlockEnd && paddingStylesMap.paddingBlockEnd[paddingBlockEnd], paddingInline && paddingStylesMap.paddingInline[paddingInline], paddingInlineStart && paddingStylesMap.paddingInlineStart[paddingInlineStart], paddingInlineEnd && paddingStylesMap.paddingInlineEnd[paddingInlineEnd],
56
+ css: [baseStyles, backgroundColor && backgroundColorStylesMap[backgroundColor], isSurfaceColorToken(backgroundColor) && surfaceColorStylesMap[backgroundColor], padding && paddingStylesMap.padding[padding], paddingBlock && paddingStylesMap.paddingBlock[paddingBlock], paddingBlockStart && paddingStylesMap.paddingBlockStart[paddingBlockStart], paddingBlockEnd && paddingStylesMap.paddingBlockEnd[paddingBlockEnd], paddingInline && paddingStylesMap.paddingInline[paddingInline], paddingInlineStart && paddingStylesMap.paddingInlineStart[paddingInlineStart], paddingInlineEnd && paddingStylesMap.paddingInlineEnd[paddingInlineEnd],
57
57
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
58
58
  className],
59
59
  "data-testid": testId
@@ -0,0 +1,34 @@
1
+ import React, { createContext, useContext } from 'react';
2
+
3
+ // Allows support for heading levels 1-9 via aria-level
4
+
5
+ var HeadingContext = /*#__PURE__*/createContext(0);
6
+ export var useHeadingElement = function useHeadingElement() {
7
+ return useContext(HeadingContext);
8
+ };
9
+ /**
10
+ * __Heading context__
11
+ *
12
+ * The HeadingContext
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * // Will correctly infer the heading level
17
+ * <HeadingContext value={1}>
18
+ * <Heading>H1</Heading>
19
+ * <HeadingContext>
20
+ * <Heading>H2</Heading>
21
+ * </HeadingContext>
22
+ * </HeadingContext>
23
+ * ```
24
+ */
25
+ var HeadingContextProvider = function HeadingContextProvider(_ref) {
26
+ var children = _ref.children,
27
+ value = _ref.value;
28
+ var parentHeadingLevel = useHeadingElement();
29
+ var headingLevel = parentHeadingLevel + 1;
30
+ return /*#__PURE__*/React.createElement(HeadingContext.Provider, {
31
+ value: value || headingLevel
32
+ }, children);
33
+ };
34
+ export default HeadingContextProvider;
@@ -0,0 +1,87 @@
1
+ /** @jsx jsx */
2
+ import { css, jsx } from '@emotion/react';
3
+ import { useHeadingElement } from './heading-context';
4
+ // https://atlassian.design/foundations/typography
5
+ var levelMap = {
6
+ xxl: 'h1',
7
+ xl: 'h2',
8
+ lg: 'h3',
9
+ md: 'h4',
10
+ sm: 'h5',
11
+ xs: 'h6',
12
+ xxs: 'div'
13
+ };
14
+ var headingResetStyles = css({
15
+ color: "var(--ds-text, #172B4D)",
16
+ letterSpacing: 'normal',
17
+ marginBlock: 0,
18
+ textTransform: 'none'
19
+ });
20
+ var headingStylesMap = {
21
+ xxl: css({
22
+ font: "var(--ds-font-heading-xxl, inherit)"
23
+ }),
24
+ xl: css({
25
+ font: "var(--ds-font-heading-xl, inherit)"
26
+ }),
27
+ lg: css({
28
+ font: "var(--ds-font-heading-lg, inherit)"
29
+ }),
30
+ md: css({
31
+ font: "var(--ds-font-heading-md, inherit)"
32
+ }),
33
+ sm: css({
34
+ font: "var(--ds-font-heading-sm, inherit)"
35
+ }),
36
+ xs: css({
37
+ font: "var(--ds-font-heading-xs, inherit)"
38
+ }),
39
+ xxs: css({
40
+ font: "var(--ds-font-heading-xxs, inherit)"
41
+ })
42
+ };
43
+ var inverseStyles = css({
44
+ color: "var(--ds-text-inverse, #FFF)"
45
+ });
46
+ /**
47
+ * __Heading__
48
+ *
49
+ * A heading is a typography component used to display text in different sizes and formats.
50
+ *
51
+ * @example
52
+ *
53
+ * ```jsx
54
+ * import Heading from '@atlaskit/heading';
55
+ *
56
+ * const HeadingXXL = () => (
57
+ * <Heading level="xxl">XXL</Heading>
58
+ * );
59
+ * ```
60
+ */
61
+ var Heading = function Heading(_ref) {
62
+ var children = _ref.children,
63
+ level = _ref.level,
64
+ id = _ref.id,
65
+ testId = _ref.testId,
66
+ as = _ref.as,
67
+ _ref$color = _ref.color,
68
+ color = _ref$color === void 0 ? 'default' : _ref$color;
69
+ if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'production' && as && typeof as !== 'string') {
70
+ throw new Error('`as` prop should be a string.');
71
+ }
72
+ var hLevel = useHeadingElement();
73
+ /**
74
+ * Order here is important, we for now apply
75
+ * 1. user choice
76
+ * 2. inferred a11y level
77
+ * 3. default final fallback
78
+ */
79
+ var Markup = as || hLevel && (hLevel > 6 ? 'div' : "h".concat(hLevel)) || levelMap[level];
80
+ return jsx(Markup, {
81
+ id: id,
82
+ "data-testid": testId,
83
+ role: Markup === 'div' ? 'heading' : undefined,
84
+ css: [headingResetStyles, level && headingStylesMap[level], color === 'inverse' && inverseStyles]
85
+ }, children);
86
+ };
87
+ export default Heading;
@@ -0,0 +1,19 @@
1
+ import { createContext, useContext } from 'react';
2
+ /**
3
+ * __Surface context__
4
+ *
5
+ * A surface context provides context information on the current background (if set).
6
+ */
7
+ export var SurfaceContext = /*#__PURE__*/createContext('elevation.surface');
8
+
9
+ /**
10
+ * __useSurface__
11
+ *
12
+ * Return the current surface. If no parent sets a surface color it falls back to the default surface.
13
+ *
14
+ * @see SurfaceContext
15
+ */
16
+ export var useSurface = function useSurface() {
17
+ return useContext(SurfaceContext);
18
+ };
19
+ SurfaceContext.displayName = 'SurfaceProvider';
@@ -0,0 +1,128 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ var _excluded = ["children"];
4
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
+ /** @jsx jsx */
7
+ import { createContext, Fragment, useContext } from 'react';
8
+ import { css, jsx } from '@emotion/react';
9
+ import invariant from 'tiny-invariant';
10
+ import { bodyTextStylesMap
11
+
12
+ // textColorStylesMap,
13
+ , uiTextStylesMap } from '../xcss/style-maps.partial';
14
+
15
+ // import surfaceColorMap from '../internal/color-map';
16
+
17
+ // import { useSurface } from './internal/surface-provider';
18
+ var asAllowlist = ['span', 'p', 'strong', 'em', 'label'];
19
+ var variantStyles = _objectSpread(_objectSpread({}, bodyTextStylesMap), uiTextStylesMap);
20
+ var textAlignMap = {
21
+ center: css({
22
+ textAlign: 'center'
23
+ }),
24
+ end: css({
25
+ textAlign: 'end'
26
+ }),
27
+ start: css({
28
+ textAlign: 'start'
29
+ })
30
+ };
31
+
32
+ // p tag has padding on top in css-reset. dont know if we want to add it here
33
+ var baseStyles = css({
34
+ margin: "var(--ds-space-0, 0px)",
35
+ padding: "var(--ds-space-0, 0px)"
36
+ });
37
+ var truncateStyles = css({
38
+ overflow: 'hidden',
39
+ textOverflow: 'ellipsis',
40
+ whiteSpace: 'nowrap'
41
+ });
42
+
43
+ // TODO
44
+ // const asElementStyles: Record<AsElement, SerializedStyles> = {
45
+ // abbr: css({
46
+ // borderBottom: `1px ${token('color.border', '#ccc')} dotted`,
47
+ // cursor: 'help',
48
+ // }),
49
+ // };
50
+
51
+ /**
52
+ * Custom hook designed to abstract the parsing of the color props and make it clearer in the future how color is reconciled between themes and tokens.
53
+ */
54
+ // const useColor = (colorProp: TextColor): NonNullable<TextColor> => {
55
+ // const surface = useSurface();
56
+ // const inverseTextColor =
57
+ // surfaceColorMap[surface as keyof typeof surfaceColorMap];
58
+
59
+ // /**
60
+ // * Where the color of the surface is inverted we override the user choice
61
+ // * as there is no valid choice that is not covered by the override.
62
+ // */
63
+ // const color = inverseTextColor ?? colorProp;
64
+
65
+ // return color;
66
+ // };
67
+
68
+ var HasTextAncestorContext = /*#__PURE__*/createContext(false);
69
+ var useHasTextAncestor = function useHasTextAncestor() {
70
+ return useContext(HasTextAncestorContext);
71
+ };
72
+
73
+ /**
74
+ * __Text__
75
+ *
76
+ * Text is a primitive component that has the Atlassian Design System's design guidelines baked in.
77
+ * This includes considerations for text attributes such as color, font size, font weight, and line height.
78
+ * It renders a `span` by default.
79
+ *
80
+ * @internal
81
+ */
82
+ var Text = function Text(_ref) {
83
+ var children = _ref.children,
84
+ props = _objectWithoutProperties(_ref, _excluded);
85
+ var asElement = props.as,
86
+ _props$shouldTruncate = props.shouldTruncate,
87
+ shouldTruncate = _props$shouldTruncate === void 0 ? false : _props$shouldTruncate,
88
+ textAlign = props.textAlign,
89
+ testId = props.testId,
90
+ id = props.id,
91
+ variant = props.variant;
92
+ var Component = asElement;
93
+ if (!Component) {
94
+ if (variant.includes('body')) {
95
+ Component = 'p';
96
+ } else {
97
+ // ui text and default => span
98
+ Component = 'span';
99
+ }
100
+ }
101
+ invariant(asAllowlist.includes(Component), "@atlaskit/ds-explorations: Text received an invalid \"as\" value of \"".concat(Component, "\""));
102
+ // const color = useColor(colorProp!);
103
+ var isWrapped = useHasTextAncestor();
104
+
105
+ /**
106
+ * If the text is already wrapped and applies no props we can just
107
+ * render the children directly as a fragment.
108
+ */
109
+ if (isWrapped && Object.keys(props).length === 0) {
110
+ return jsx(Fragment, null, children);
111
+ }
112
+ var component = jsx(Component
113
+ // style={UNSAFE_style}
114
+ , {
115
+ css: [baseStyles, variant && variantStyles[variant],
116
+ // color && textColorMap[color],
117
+ // colorProp && textColorMap[colorProp],
118
+ shouldTruncate && truncateStyles, textAlign && textAlignMap[textAlign]],
119
+ "data-testid": testId,
120
+ id: id
121
+ }, children);
122
+ return isWrapped ?
123
+ // no need to re-apply context if the text is already wrapped
124
+ component : jsx(HasTextAncestorContext.Provider, {
125
+ value: true
126
+ }, component);
127
+ };
128
+ export default Text;