@primer/components 31.2.0-rc.58429c9f → 31.2.0-rc.5ccefd7d

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.
@@ -3,6 +3,8 @@ title: Theming
3
3
  description: Theming in Primer React is made possible by a theme object that defines your application's colors, spacing, fonts, and more.
4
4
  ---
5
5
 
6
+ import Code from '@primer/gatsby-theme-doctocat/src/components/code'
7
+
6
8
  ## ThemeProvider
7
9
 
8
10
  To give components access to the theme object, you must add `ThemeProvider` to the root of your application:
@@ -50,6 +52,27 @@ Some components may break if your custom theme does not include all the same key
50
52
 
51
53
  You can reference theme values in your application using [system props](/system-props), the [`sx` prop](/overriding-styles), the `themeGet` function, or the `useTheme` hook.
52
54
 
55
+ <Note variant="warning">
56
+
57
+ Only use `theme` objects accessed via Primer's theme context to ensure your application’s styling draws from the same theme as Primer components’ internal styling. The `sx` prop, styled system props, `themeGet`, and `useTheme` all use the theme from context.
58
+
59
+ <DoDontContainer>
60
+ <Do>
61
+ <Code className="language-jsx">
62
+ {`<Box textShadow="shadow.medium">`}
63
+ </Code>
64
+ <Caption>Use the theme from the same context as Primer.</Caption>
65
+ </Do>
66
+ <Dont>
67
+ <Code className="language-jsx">
68
+ {`import {theme} from '@primer/components'\n\n<Box textShadow={theme.shadows.shadow.medium}>`}
69
+ </Code>
70
+ <Caption>Don't style components with any other instance of theme</Caption>
71
+ </Dont>
72
+ </DoDontContainer>
73
+
74
+ </Note>
75
+
53
76
  ### System props and the `sx` prop
54
77
 
55
78
  Some [system props](/system-props) and [`sx` prop](/overriding-styles) keys are theme-aware. For example, the `bg` prop maps to the `colors` theme key which means you can use the `bg` prop to reference values in the `colors` object:
@@ -45,7 +45,7 @@ function Header({
45
45
  return /*#__PURE__*/_react.default.createElement(StyledHeader, _extends({
46
46
  role: "heading",
47
47
  variant: variant
48
- }, props), title, auxiliaryText && /*#__PURE__*/_react.default.createElement("span", null, "auxiliaryText"));
48
+ }, props), title, auxiliaryText && /*#__PURE__*/_react.default.createElement("span", null, auxiliaryText));
49
49
  }
50
50
 
51
51
  Header.displayName = "Header";
@@ -1,3 +1,4 @@
1
+ import { Union } from 'ts-toolbelt';
1
2
  import { KeyPaths } from '../utils/types/KeyPaths';
2
3
  declare type NestedObject = {
3
4
  a: string;
@@ -6,5 +7,5 @@ declare type NestedObject = {
6
7
  b2: string;
7
8
  };
8
9
  };
9
- export declare function generatesKeyPathsFromObject(x: KeyPaths<NestedObject>): 'a' | 'b.b1' | 'b.b2';
10
+ export declare function generatesKeyPathsFromObject(x: Union.Diff<KeyPaths<NestedObject>, 'a' | 'b.b1' | 'b.b2'>): never;
10
11
  export {};
@@ -1,3 +1,3 @@
1
1
  export declare type KeyPaths<O extends Record<string, unknown>> = {
2
- [K in keyof O]: K extends string ? (O[K] extends string ? `${K}` : `${K}.${KeyPaths<O[K]>}`) : never;
2
+ [K in keyof O]: K extends string ? O[K] extends string ? `${K}` : `${K}.${KeyPaths<O[K]>}` : never;
3
3
  }[keyof O];
@@ -28,6 +28,6 @@ export function Header({
28
28
  return /*#__PURE__*/React.createElement(StyledHeader, _extends({
29
29
  role: "heading",
30
30
  variant: variant
31
- }, props), title, auxiliaryText && /*#__PURE__*/React.createElement("span", null, "auxiliaryText"));
31
+ }, props), title, auxiliaryText && /*#__PURE__*/React.createElement("span", null, auxiliaryText));
32
32
  }
33
33
  Header.displayName = "Header";
@@ -1,3 +1,4 @@
1
+ import { Union } from 'ts-toolbelt';
1
2
  import { KeyPaths } from '../utils/types/KeyPaths';
2
3
  declare type NestedObject = {
3
4
  a: string;
@@ -6,5 +7,5 @@ declare type NestedObject = {
6
7
  b2: string;
7
8
  };
8
9
  };
9
- export declare function generatesKeyPathsFromObject(x: KeyPaths<NestedObject>): 'a' | 'b.b1' | 'b.b2';
10
+ export declare function generatesKeyPathsFromObject(x: Union.Diff<KeyPaths<NestedObject>, 'a' | 'b.b1' | 'b.b2'>): never;
10
11
  export {};
@@ -1,3 +1,3 @@
1
1
  export declare type KeyPaths<O extends Record<string, unknown>> = {
2
- [K in keyof O]: K extends string ? (O[K] extends string ? `${K}` : `${K}.${KeyPaths<O[K]>}`) : never;
2
+ [K in keyof O]: K extends string ? O[K] extends string ? `${K}` : `${K}.${KeyPaths<O[K]>}` : never;
3
3
  }[keyof O];
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@primer/components",
3
- "version": "31.0.1",
3
+ "version": "31.1.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@primer/components",
9
- "version": "31.0.1",
9
+ "version": "31.1.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@primer/octicons-react": "^13.0.0",
@@ -100,6 +100,7 @@
100
100
  "size-limit": "5.0.2",
101
101
  "storybook-addon-performance": "0.16.1",
102
102
  "styled-components": "4.4.1",
103
+ "ts-toolbelt": "9.6.0",
103
104
  "typescript": "4.2.2"
104
105
  },
105
106
  "peerDependencies": {
@@ -35601,6 +35602,12 @@
35601
35602
  }
35602
35603
  }
35603
35604
  },
35605
+ "node_modules/ts-toolbelt": {
35606
+ "version": "9.6.0",
35607
+ "resolved": "https://registry.npmjs.org/ts-toolbelt/-/ts-toolbelt-9.6.0.tgz",
35608
+ "integrity": "sha512-nsZd8ZeNUzukXPlJmTBwUAuABDe/9qtVDelJeT/qW0ow3ZS3BsQJtNkan1802aM9Uf68/Y8ljw86Hu0h5IUW3w==",
35609
+ "dev": true
35610
+ },
35604
35611
  "node_modules/tsconfig-paths": {
35605
35612
  "version": "3.9.0",
35606
35613
  "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz",
@@ -64793,6 +64800,12 @@
64793
64800
  "integrity": "sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw==",
64794
64801
  "dev": true
64795
64802
  },
64803
+ "ts-toolbelt": {
64804
+ "version": "9.6.0",
64805
+ "resolved": "https://registry.npmjs.org/ts-toolbelt/-/ts-toolbelt-9.6.0.tgz",
64806
+ "integrity": "sha512-nsZd8ZeNUzukXPlJmTBwUAuABDe/9qtVDelJeT/qW0ow3ZS3BsQJtNkan1802aM9Uf68/Y8ljw86Hu0h5IUW3w==",
64807
+ "dev": true
64808
+ },
64796
64809
  "tsconfig-paths": {
64797
64810
  "version": "3.9.0",
64798
64811
  "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/components",
3
- "version": "31.2.0-rc.58429c9f",
3
+ "version": "31.2.0-rc.5ccefd7d",
4
4
  "description": "Primer react components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",
@@ -134,6 +134,7 @@
134
134
  "size-limit": "5.0.2",
135
135
  "storybook-addon-performance": "0.16.1",
136
136
  "styled-components": "4.4.1",
137
+ "ts-toolbelt": "9.6.0",
137
138
  "typescript": "4.2.2"
138
139
  },
139
140
  "peerDependencies": {
@@ -68,7 +68,7 @@ export function Header({
68
68
  return (
69
69
  <StyledHeader role="heading" variant={variant} {...props}>
70
70
  {title}
71
- {auxiliaryText && <span>auxiliaryText</span>}
71
+ {auxiliaryText && <span>{auxiliaryText}</span>}
72
72
  </StyledHeader>
73
73
  )
74
74
  }
@@ -1,3 +1,4 @@
1
+ import {Union} from 'ts-toolbelt'
1
2
  import {KeyPaths} from '../utils/types/KeyPaths'
2
3
 
3
4
  type NestedObject = {
@@ -8,6 +9,6 @@ type NestedObject = {
8
9
  }
9
10
  }
10
11
 
11
- export function generatesKeyPathsFromObject(x: KeyPaths<NestedObject>): 'a' | 'b.b1' | 'b.b2' {
12
+ export function generatesKeyPathsFromObject(x: Union.Diff<KeyPaths<NestedObject>, 'a' | 'b.b1' | 'b.b2'>): never {
12
13
  return x
13
14
  }
@@ -77,7 +77,7 @@ export const buttonGroup = (args: StrictButtonStyleProps) => (
77
77
  export const buttonTableList = (args: ButtonStyleProps) => (
78
78
  <ButtonTableList {...args}>Button Table List</ButtonTableList>
79
79
  )
80
- export const disabledButton = (args: ButtonStyleProps) => {
80
+ export const disabledButton = (args: StrictButtonStyleProps) => {
81
81
  const props = {disabled: true, ...args}
82
82
  return <Button {...props}>Disabled</Button>
83
83
  }
@@ -1,4 +1,10 @@
1
1
  // Produces a union of dot-delimited keypaths to the string values in a nested object:
2
2
  export type KeyPaths<O extends Record<string, unknown>> = {
3
- [K in keyof O]: K extends string ? (O[K] extends string ? `${K}` : `${K}.${KeyPaths<O[K]>}`) : never
3
+ [K in keyof O]: K extends string
4
+ ? O[K] extends string
5
+ ? `${K}`
6
+ : // eslint-disable-next-line @typescript-eslint/ban-ts-comment
7
+ // @ts-ignore TypeScript has bested me, but the KeyPaths type is tested.
8
+ `${K}.${KeyPaths<O[K]>}`
9
+ : never
4
10
  }[keyof O]