Skip to content

Commit 62ab0f8

Browse files
committed
refactor(many): remove checkerboard background in examples, fix TS type errors, use types from react-docgen
The checkedboard needed to go because dark squared did not meet WCAG 2.1 AA contrast requirements against red error text. Also type checking of docs during bootstrap and use types from react-docgen Fixes INSTUI-4282
1 parent 52dc340 commit 62ab0f8

File tree

32 files changed

+141
-347
lines changed

32 files changed

+141
-347
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/__docs__/buildScripts/DataTypes.mts

Lines changed: 2 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
// This is the format of the saved JSON files
2626
import { Documentation } from 'react-docgen'
27+
import type { Theme } from '@instructure/ui-themes'
2728

2829
type ProcessedFile =
2930
Documentation &
@@ -92,99 +93,6 @@ type JSDocFunctionReturns = {
9293
names: string[]
9394
}
9495
}
95-
// TODO these are from React-docgen Documentation.d.ts,
96-
// remove when react-docgen exports them
97-
interface MethodParameter {
98-
name: string;
99-
description?: string;
100-
optional: boolean;
101-
type?: TypeDescriptor<FunctionSignatureType> | null;
102-
}
103-
104-
interface MethodReturn {
105-
description?: string;
106-
type: TypeDescriptor<FunctionSignatureType> | undefined;
107-
}
108-
109-
interface PropDescriptor {
110-
type?: PropTypeDescriptor;
111-
flowType?: TypeDescriptor<FunctionSignatureType>;
112-
tsType?: TypeDescriptor<TSFunctionSignatureType>;
113-
required?: boolean;
114-
defaultValue?: DefaultValueDescriptor;
115-
description?: string;
116-
}
117-
118-
interface PropTypeDescriptor {
119-
name: 'any' | 'array' | 'arrayOf' | 'bool' | 'custom' | 'element' | 'elementType' | 'enum' | 'exact' | 'func' | 'instanceOf' | 'node' | 'number' | 'object' | 'objectOf' | 'shape' | 'string' | 'symbol' | 'union';
120-
value?: unknown;
121-
raw?: string;
122-
computed?: boolean;
123-
description?: string;
124-
required?: boolean;
125-
}
126-
127-
type TypeDescriptor<T = FunctionSignatureType> = ElementsType<T> | LiteralType | ObjectSignatureType<T> | SimpleType | T;
128-
129-
interface DefaultValueDescriptor {
130-
value: unknown;
131-
computed: boolean;
132-
}
133-
interface BaseType {
134-
required?: boolean;
135-
nullable?: boolean;
136-
alias?: string;
137-
}
138-
interface SimpleType extends BaseType {
139-
name: string;
140-
raw?: string;
141-
}
142-
interface LiteralType extends BaseType {
143-
name: 'literal';
144-
value: string;
145-
}
146-
interface ElementsType<T = FunctionSignatureType> extends BaseType {
147-
name: string;
148-
raw: string;
149-
elements: Array<TypeDescriptor<T>>;
150-
}
151-
152-
interface FunctionArgumentType<T> {
153-
name: string
154-
type?: TypeDescriptor<T>
155-
rest?: boolean
156-
}
157-
158-
interface FunctionSignatureType extends BaseType {
159-
name: 'signature';
160-
type: 'function';
161-
raw: string;
162-
signature: {
163-
arguments: Array<FunctionArgumentType<FunctionSignatureType>>;
164-
return?: TypeDescriptor<FunctionSignatureType>;
165-
};
166-
}
167-
interface TSFunctionSignatureType extends FunctionSignatureType {
168-
signature: {
169-
arguments: Array<FunctionArgumentType<TSFunctionSignatureType>>;
170-
return?: TypeDescriptor<TSFunctionSignatureType>;
171-
this?: TypeDescriptor<TSFunctionSignatureType>;
172-
};
173-
}
174-
interface ObjectSignatureType<T = FunctionSignatureType> extends BaseType {
175-
name: 'signature';
176-
type: 'object';
177-
raw: string;
178-
signature: {
179-
properties: Array<{
180-
key: TypeDescriptor<T> | string;
181-
value: TypeDescriptor<T>;
182-
description?: string;
183-
}>;
184-
constructor?: TypeDescriptor<T>;
185-
};
186-
}
187-
// end react-docgen part
18896

18997
type LibraryOptions = {
19098
name: string
@@ -237,7 +145,7 @@ type MainIconsData = {
237145
}
238146

239147
type MainDocsData = {
240-
themes: Record<string, { resource: any; requirePath: string }>
148+
themes: Record<string, { resource: Theme; requirePath: string }>
241149
library: LibraryOptions
242150
} & ParsedDoc
243151

@@ -246,16 +154,6 @@ export type {
246154
PackagePathData,
247155
YamlMetaInfo,
248156
JSDocFunctionReturns,
249-
PropDescriptor,
250-
MethodParameter,
251-
MethodReturn,
252-
TypeDescriptor,
253-
TSFunctionSignatureType,
254-
SimpleType,
255-
LiteralType,
256-
ElementsType,
257-
ObjectSignatureType,
258-
BaseType,
259157
LibraryOptions,
260158
Glyph,
261159
MainDocsData,

packages/__docs__/functionalComponentThemes.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@
2222
* SOFTWARE.
2323
*/
2424

25-
const themes = {
25+
import type { Theme } from '@instructure/ui-themes'
26+
// eslint-disable-next-line no-restricted-imports
27+
import type { ThemeFunctionsFunctional } from './src/App/props'
28+
29+
const themes: ThemeFunctionsFunctional = {
2630
// TODO figure out subcomponents e.g.: Table.Cell
27-
avatar: async (theme) =>
28-
(await import('@instructure/ui-avatar/src/Avatar/theme.ts')).default(theme)
31+
Avatar: async (theme: Theme) =>
32+
(await import('@instructure/ui-avatar/src/Avatar/theme')).default(theme)
2933
}
3034

3135
export default themes

packages/__docs__/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"jsdoc-api": "^8.1.1",
138138
"mkdirp": "^3.0.1",
139139
"raw-loader": "^4.0.2",
140-
"react-docgen": "^7.1.0",
140+
"react-docgen": "^7.1.1",
141141
"svg-inline-loader": "^0.8.2",
142142
"webpack-bundle-analyzer": "^4.10.2"
143143
},

packages/__docs__/src/App/index.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@ import {
3232
} from 'react'
3333

3434
import { Alert } from '@instructure/ui-alerts'
35-
import {
36-
InstUISettingsProvider,
37-
withStyle,
38-
jsx,
39-
Global
40-
} from '@instructure/emotion'
35+
import { InstUISettingsProvider, withStyle, Global } from '@instructure/emotion'
4136
import { Flex } from '@instructure/ui-flex'
4237
import { Text } from '@instructure/ui-text'
4338
import { View } from '@instructure/ui-view'
@@ -398,7 +393,6 @@ class App extends Component<AppProps, AppState> {
398393

399394
const { layout } = this.state
400395
const smallerScreens = layout === 'small' || layout === 'medium'
401-
402396
const themeContent = (
403397
<View
404398
as="div"

packages/__docs__/src/App/props.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import type {
3030
ProcessedFile
3131
} from '../../buildScripts/DataTypes.mts'
3232
import type { DocDataType } from '../Document/props'
33+
import type { Theme } from '@instructure/ui-themes'
34+
import type { ThemeVariables } from '@instructure/shared-types'
3335

3436
type AppOwnProps = {
3537
trayWidth: number
@@ -97,8 +99,18 @@ type AppState = {
9799
currentDocData?: DocData
98100
}
99101

102+
type ThemeFunctionsClassic = {
103+
[K in keyof ThemeVariables]: (theme: Theme) => ThemeVariables[K]
104+
}
105+
106+
export type ThemeFunctionsFunctional = Partial<{
107+
[K in keyof ThemeVariables]: (theme: Theme) => Promise<ThemeVariables[K]>
108+
}>
109+
100110
type DocData = ProcessedFile & {
101-
componentInstance: any
111+
componentInstance: Record<string, any> & {
112+
generateComponentTheme?: ThemeFunctionsClassic[keyof ThemeFunctionsClassic]
113+
}
102114
children: DocDataType[]
103115
}
104116

packages/__docs__/src/ColorTable/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ import { ColorTableProps } from './props'
3232

3333
class ColorTable extends Component<ColorTableProps> {
3434
renderRows() {
35-
const colorMap = Object.keys(this.props.colorNames).reduce((acc, color) => {
35+
const colorMap: Record<string, string> = Object.keys(
36+
this.props.colorNames
37+
).reduce((acc, color) => {
3638
const hex = this.props.colorNames[color]
3739
return { ...acc, [hex]: color }
3840
}, {})

packages/__docs__/src/ColorTable/props.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import type { PropValidators } from '@instructure/shared-types'
2525
import PropTypes from 'prop-types'
2626

2727
type ColorTableOwnProps = {
28-
colors: any
29-
colorNames: any
28+
colors: Record<string, string>
29+
colorNames: Record<string, string>
3030
}
3131

3232
type PropKeys = keyof ColorTableOwnProps

packages/__docs__/src/Document/index.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,20 @@ class Document extends Component<DocumentProps, DocumentState> {
7373

7474
fetchGenerateComponentTheme = async () => {
7575
const { doc, themeVariables } = this.props
76-
const generateComponentTheme =
77-
doc?.componentInstance?.generateComponentTheme
76+
const generateTheme = doc?.componentInstance?.generateComponentTheme
77+
const generateThemeFunctional =
78+
functionalComponentThemes[
79+
doc.id as keyof typeof functionalComponentThemes
80+
]
7881
if (
79-
generateComponentTheme &&
80-
typeof generateComponentTheme === 'function' &&
82+
generateTheme &&
83+
typeof generateTheme === 'function' &&
8184
themeVariables
8285
) {
83-
this.setState({ componentTheme: generateComponentTheme(themeVariables) })
84-
} else {
85-
const componentTheme = await functionalComponentThemes[
86-
doc.id.toLowerCase()
87-
](themeVariables)
88-
this.setState({ componentTheme })
86+
this.setState({ componentTheme: generateTheme(themeVariables) })
87+
} else if (generateThemeFunctional && themeVariables) {
88+
const componentTheme = await generateThemeFunctional(themeVariables)
89+
this.setState({ componentTheme: componentTheme })
8990
}
9091
}
9192

packages/__docs__/src/Document/props.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,16 @@
2424

2525
import PropTypes from 'prop-types'
2626
import type { ComponentStyle, WithStyleProps } from '@instructure/emotion'
27-
import type {
28-
PropValidators,
29-
BaseThemeVariables,
30-
ComponentTheme
31-
} from '@instructure/shared-types'
27+
import type { PropValidators, ThemeVariables } from '@instructure/shared-types'
3228
import { DocData } from '../App/props'
29+
import { Theme } from '@instructure/ui-themes'
3330

3431
type DocDataType = DocData & { legacyGitBranch?: string }
3532

3633
type DocumentOwnProps = {
3734
doc: DocDataType
3835
description: string
39-
themeVariables?: BaseThemeVariables & { key: string }
36+
themeVariables?: Theme
4037
repository?: string
4138
layout?: 'small' | 'medium' | 'large' | 'x-large'
4239
}
@@ -73,7 +70,7 @@ type DocumentStyle = ComponentStyle<'githubCornerOctoArm' | 'githubCorner'>
7370
type DocumentState = {
7471
selectedDetailsTabIndex: number
7572
pageRef: HTMLDivElement | null
76-
componentTheme: ComponentTheme
73+
componentTheme: Partial<ThemeVariables[keyof ThemeVariables]>
7774
}
7875

7976
const allowedProps: AllowedPropKeys = [

0 commit comments

Comments
 (0)