Skip to content

Commit 09f3b60

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 1e36568 commit 09f3b60

File tree

28 files changed

+105
-326
lines changed

28 files changed

+105
-326
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 { BaseTheme } from '@instructure/shared-types'
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: BaseTheme; 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__/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/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/Figure/props.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ type FigureTheme = {
5353
shadow: Shadows['depth2']
5454
captionFontFamily: Typography['fontFamily']
5555
captionFontSize: Typography['fontSizeSmall']
56-
captionBackground: Colors['porcelain']
56+
captionBackground: Colors['contrasts']['green1212']
5757
captionPadding: Spacing['small']
58-
captionColor: Colors['oxford']
58+
captionColor: Colors['contrasts']['grey100100']
5959
borderWidth: Border['widthMedium']
60-
borderColor: Colors['oxford']
60+
borderColor: Colors['contrasts']['grey100100']
6161
contentPadding: Spacing['medium']
62-
contentBackground: Colors['white']
63-
yesColor: Colors['shamrock']
64-
noColor: Colors['crimson']
65-
a11yColor: Colors['electric']
66-
iconColor: Colors['white']
62+
contentBackground: Colors['contrasts']['white1010']
63+
yesColor: Colors['contrasts']['green4570']
64+
noColor: Colors['contrasts']['red4570']
65+
a11yColor: Colors['contrasts']['blue4570']
66+
iconColor: Colors['contrasts']['white1010']
6767
iconContainerStacking: Stacking['above']
6868
iconContainerSize: Spacing['large']
6969
floatMargin: Spacing['large']

packages/__docs__/src/Header/index.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,7 @@ class Header extends Component<HeaderProps> {
169169
<Link href="#index" isWithinText={false} display="block">
170170
<View display="block" margin="small none none">
171171
<Text size="large">
172-
{(
173-
<span>
174-
{this.props.name} {this.props.version}
175-
</span>
176-
) || 'Documentation'}
172+
{this.props.name} {this.props.version}
177173
</Text>
178174
</View>
179175
</Link>

packages/__docs__/src/Nav/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
* SOFTWARE.
2323
*/
2424

25-
import React, { Children, Component } from 'react'
25+
import React, { Component } from 'react'
2626

2727
import { IconSearchLine } from '@instructure/ui-icons'
2828
import { Link } from '@instructure/ui-link'
2929
import { TextInput } from '@instructure/ui-text-input'
3030
import { ScreenReaderContent } from '@instructure/ui-a11y-content'
31-
import { View } from '@instructure/ui-view'
31+
import { View, ViewOwnProps } from '@instructure/ui-view'
3232

3333
import { capitalizeFirstLetter } from '@instructure/ui-utils'
3434

@@ -119,7 +119,7 @@ class Nav extends Component<NavProps, NavState> {
119119
}): React.ReactNode {
120120
if (
121121
React.isValidElement(children) &&
122-
Children.count(children.props.children) === 0
122+
React.Children.count(children.props.children) === 0
123123
) {
124124
return
125125
}
@@ -209,9 +209,9 @@ class Nav extends Component<NavProps, NavState> {
209209
}
210210
}
211211

212-
removeFocus = (event) => {
213-
if (event.target && event.target.blur) {
214-
event.target.blur()
212+
removeFocus = (event: React.MouseEvent<ViewOwnProps>) => {
213+
if (event.target && (event.target as HTMLElement).blur) {
214+
;(event.target as HTMLElement).blur()
215215
}
216216
}
217217

packages/__docs__/src/Nav/props.ts

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

25-
import type { PropValidators } from '@instructure/shared-types'
25+
import type {
26+
OtherHTMLAttributes,
27+
PropValidators
28+
} from '@instructure/shared-types'
2629
import PropTypes from 'prop-types'
2730
type NavOwnProps = {
2831
docs: Record<string, any>
@@ -35,7 +38,7 @@ type PropKeys = keyof NavOwnProps
3538

3639
type AllowedPropKeys = Readonly<Array<PropKeys>>
3740

38-
type NavProps = NavOwnProps
41+
type NavProps = OtherHTMLAttributes<NavOwnProps> & NavOwnProps
3942

4043
const propTypes: PropValidators<PropKeys> = {
4144
docs: PropTypes.object.isRequired,

0 commit comments

Comments
 (0)