Skip to content

Commit c790958

Browse files
committed
fix(emotion,shared-types): better TS types for theme objects and their overrides
Also convert some of the final files in the docs app to TS and improve their typing TEST PLAN: Try to make various theme and override objects, they should have nice autocomplete and no errors
1 parent e9b03b2 commit c790958

File tree

15 files changed

+189
-117
lines changed

15 files changed

+189
-117
lines changed

package-lock.json

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ import '@instructure/ui-icons/es/icon-font/Solid/InstructureIcons-Solid.css'
4949
import '@instructure/ui-icons/es/icon-font/Line/InstructureIcons-Line.css'
5050

5151
import { DateTime } from '@instructure/ui-i18n'
52-
52+
// @ts-ignore webpack import
5353
import iconExample from './buildScripts/samplemedia/heart_lg.svg'
54+
// @ts-ignore webpack import
5455
import avatarSquare from './buildScripts/samplemedia/avatarSquare.jpg'
56+
// @ts-ignore webpack import
5557
import avatarPortrait from './buildScripts/samplemedia/avatarPortrait.jpg'
5658
import placeholderImage from './buildScripts/samplemedia/placeholder-image'
5759
// eslint-disable-next-line no-restricted-imports
@@ -83,7 +85,7 @@ const globals = {
8385
lorem: {
8486
sentence: () => lorem.generateWords(),
8587
paragraph: () => lorem.generateSentences(5),
86-
paragraphs: (count) =>
88+
paragraphs: (count: number) =>
8789
lorem.generateSentences(count || Math.floor(Math.random() * 10))
8890
},
8991
mirrorHorizontalPlacement,
@@ -104,7 +106,7 @@ const globals = {
104106
}
105107

106108
Object.keys(globals).forEach((key) => {
107-
global[key] = globals[key]
109+
;(global as any)[key] = globals[key]
108110
})
109111

110112
export default globals

packages/__docs__/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"react": "^18.3.1",
124124
"react-dom": "^18.3.1",
125125
"semver": "^7.6.3",
126-
"uuid": "^10.0.0",
126+
"uuid": "^11.0.3",
127127
"webpack-merge": "^6.0.1"
128128
},
129129
"devDependencies": {

packages/__docs__/src/Document/props.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424

2525
import PropTypes from 'prop-types'
26-
import { DocPropType } from '../propTypes'
2726
import type { ComponentStyle, WithStyleProps } from '@instructure/emotion'
2827
import type {
2928
PropValidators,
@@ -47,6 +46,19 @@ type AllowedPropKeys = Readonly<Array<PropKeys>>
4746

4847
type DocumentProps = DocumentOwnProps & WithStyleProps<null, DocumentStyle>
4948

49+
// TODO this does not match the TS type either fix or remove
50+
const DocPropType = PropTypes.shape({
51+
props: PropTypes.object,
52+
id: PropTypes.string.isRequired,
53+
description: PropTypes.string,
54+
undocumented: PropTypes.bool,
55+
srcPath: PropTypes.string,
56+
srcUrl: PropTypes.string,
57+
requirePath: PropTypes.string,
58+
packageName: PropTypes.string,
59+
children: PropTypes.array
60+
})
61+
5062
const propTypes: PropValidators<PropKeys> = {
5163
doc: DocPropType.isRequired,
5264
description: PropTypes.string,
@@ -70,5 +82,5 @@ const allowedProps: AllowedPropKeys = [
7082
'themeVariables'
7183
]
7284

73-
export { propTypes, allowedProps }
85+
export { propTypes, allowedProps, DocPropType }
7486
export type { DocumentProps, DocumentStyle, DocumentState, DocDataType }

packages/__docs__/src/TableOfContents/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import { element } from '@instructure/ui-prop-types'
2626
import type { PropValidators } from '@instructure/shared-types'
2727

28-
import { DocPropType } from '../propTypes'
2928
import type { DocDataType } from '../Document/props'
29+
import { DocPropType } from '../Document/props'
3030

3131
type TableOfContentsOwnProps = {
3232
doc: DocDataType

packages/__docs__/src/compileMarkdown.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,32 @@ import { Playground } from './Playground'
3939
import { compileAndRenderExample } from './compileAndRenderExample'
4040
import { Heading } from './Heading'
4141
import { Link } from './Link'
42-
import { trimIndent } from './trimIndent'
42+
43+
function trimIndent(str: string) {
44+
const lines = `${str.replace(/\r\n/g, '\n').replace(/\r/g, '\n')}\n`.split(
45+
'\n'
46+
)
47+
let indentFound = false
48+
let trimmed = ''
49+
let indent = ''
50+
lines.forEach((line, _i) => {
51+
// matches whitespace at the end of a string
52+
line.replace(/\s*$/, '')
53+
if (indentFound === false) {
54+
if (line === '') {
55+
return
56+
}
57+
// matches whitespace at the beginning of a string
58+
const matches = line.match(/^\s*/)
59+
if (matches && matches.length > 0) {
60+
indentFound = true
61+
indent = matches[0]
62+
}
63+
}
64+
trimmed += `${line.replace(new RegExp(`^${indent}`), '')}\n`
65+
})
66+
return trimmed.trim()
67+
}
4368

4469
const getHeadingId = (children: ReactNode): string => {
4570
const headingId = Children.toArray(children).reduce((id, child) => {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { App } from './App'
2929
import { InstUISettingsProvider } from '@instructure/emotion'
3030
import '../globals'
3131

32-
createRoot(document.getElementById('app')).render(
32+
createRoot(document.getElementById('app')!).render(
3333
<React.StrictMode>
3434
<InstUISettingsProvider>
3535
<App />

packages/__docs__/src/propTypes.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

packages/__docs__/src/trimIndent.js

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)