Skip to content

Commit e086e31

Browse files
committed
fix(ui-toggle-details,ui-expandable): improve typing for onClick prop
1 parent 8fffc5d commit e086e31

File tree

13 files changed

+39
-45
lines changed

13 files changed

+39
-45
lines changed

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"version": "10.23.0",
33
"npmClient": "npm",
44
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
5-
}
5+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"build:docs": "lerna run bundle --stream --scope docs-app",
3232
"build:tokens": "ui-scripts generate-all-tokens",
3333
"build:types": "tsc -b tsconfig.references.json",
34-
"build:ts": "lerna run prepare-build --stream --scope @instructure/ui-icons && npm run build:types --verbose",
34+
"build:ts": "lerna run prepare-build --stream --scope @instructure/ui-icons && npm run build:types",
3535
"clean": "node scripts/clean.js",
3636
"clean-node": "node scripts/clean.js --nuke_node",
3737
"export:icons": "lerna run export --stream --scope @instructure/ui-icons",

packages/ui-expandable/src/Expandable/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { createChainedFunction } from '@instructure/ui-utils'
2626

2727
import { propTypes, allowedProps } from './props'
2828
import type { ExpandableProps, ExpandableState } from './props'
29+
import type { ViewProps } from '@instructure/ui-view'
2930

3031
import { withDeterministicId } from '@instructure/ui-react-utils'
3132

@@ -86,7 +87,9 @@ class Expandable extends Component<ExpandableProps, ExpandableState> {
8687
}
8788
}
8889

89-
handleToggle = (event: React.MouseEvent) => {
90+
handleToggle = (
91+
event: React.MouseEvent<ViewProps> | React.KeyboardEvent<ViewProps>
92+
) => {
9093
if (!this.isControlled()) {
9194
this.setState(toggleExpanded)
9295
}

packages/ui-expandable/src/Expandable/props.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,19 @@ import { controllable } from '@instructure/ui-prop-types'
2929

3030
import type { PropValidators } from '@instructure/shared-types'
3131
import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
32+
import type { ViewProps } from '@instructure/ui-view'
3233

3334
type ExpandableToggleProps = (props?: {
34-
onClick?: React.MouseEventHandler
35+
onClick?: (
36+
event: React.KeyboardEvent<ViewProps> | React.MouseEvent<ViewProps>
37+
) => void
3538
[key: string]: unknown
3639
}) => {
3740
'aria-controls': string
3841
'aria-expanded': boolean
39-
onClick: (event: React.MouseEvent) => void
42+
onClick: (
43+
event: React.KeyboardEvent<ViewProps> | React.MouseEvent<ViewProps>
44+
) => void
4045
[key: string]: unknown
4146
}
4247

@@ -69,7 +74,10 @@ type ExpandableOwnProps = {
6974
/**
7075
* Function invoked when this component is expanded/collapsed
7176
*/
72-
onToggle?: (event: React.MouseEvent, expanded: boolean) => void
77+
onToggle?: (
78+
event: React.KeyboardEvent<ViewProps> | React.MouseEvent<ViewProps>,
79+
expanded: boolean
80+
) => void
7381

7482
/**
7583
* Must be a function that returns a JSX element. It receives and object which

packages/ui-scripts/lib/build/babel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export default {
6868
babelArgs = babelArgs.concat([
6969
src,
7070
'--ignore',
71-
'src/**/*.test.js,src/**/__tests__/**'
71+
'src/**/*.test.js,src/**/__tests__/**',
72+
'--quiet'
7273
])
7374

7475
let envVars = {}

packages/ui-scripts/lib/build/generate-all-tokens.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424

2525
import path from 'path'
26-
import fs from 'fs'
2726
import { error } from '@instructure/command-utils'
2827
import { handleMapJSTokensToSource } from '../utils/handle-map-js-tokens-to-source.js'
2928
import { handleGenerateTokens } from '../utils/handle-generate-tokens.js'
@@ -91,21 +90,7 @@ export default {
9190
? path.join(themePath, outputDir, themeKey)
9291
: path.join(themePath, outputDir)
9392
const sourcePath = path.join(outputPath, 'source.json')
94-
// this is just a debug code to find the JSON error here that occurs only in CI
95-
// eslint-disable-next-line no-console
96-
console.log(
97-
'!!!!! starting',
98-
themeKey,
99-
sourceTokens,
100-
outputPath,
101-
sourcePath,
102-
fs.existsSync(sourcePath)
103-
)
104-
// eslint-disable-next-line no-console
105-
console.log(
106-
'!!!! styleDictionarySource',
107-
JSON.stringify(styleDictionarySource)?.substring(0, 400)
108-
)
93+
10994
generators.push(
11095
handleGenerateTokens({
11196
themeKey,

packages/ui-scripts/lib/utils/handle-generate-tokens.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,12 @@ export async function handleGenerateTokens({
3737
fs.mkdirSync(dir, { recursive: true })
3838
}
3939
fs.writeFileSync(sourcePath, JSON.stringify(styleDictionarySource))
40-
// this is just a debug code to find the JSON error here that occurs only in CI
41-
// eslint-disable-next-line no-console
42-
console.log(
43-
'!!!! handleGenerateTokens',
44-
sourcePath,
45-
fs.existsSync(sourcePath),
46-
JSON.stringify(styleDictionarySource)?.substring(0, 400)
47-
)
40+
4841
const dictionary = new StyleDictionary({
4942
source: [sourcePath],
43+
log: {
44+
verbosity: 'silent' // silent to hide success messages, fatal error should still be logged
45+
},
5046
platforms: {
5147
scss: {
5248
transformGroup: 'scss',

packages/ui-toggle-details/src/ToggleDetails/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import generateComponentTheme from './theme'
3939
import type { ToggleDetailsProps } from './props'
4040
import { allowedProps, propTypes } from './props'
4141
import type { ExpandableToggleProps } from '@instructure/ui-expandable'
42+
import type { ViewProps } from '@instructure/ui-view'
4243

4344
/**
4445
---
@@ -168,7 +169,10 @@ class ToggleDetails extends Component<ToggleDetailsProps> {
168169
return <div css={this.props.styles?.content}>{this.props.children}</div>
169170
}
170171

171-
handleToggle = (event: React.MouseEvent, expanded: boolean) => {
172+
handleToggle = (
173+
event: React.KeyboardEvent<ViewProps> | React.MouseEvent<ViewProps>,
174+
expanded: boolean
175+
) => {
172176
if (typeof this.props.onToggle === 'function') {
173177
this.props.onToggle(event, expanded)
174178
}

packages/ui-toggle-details/src/ToggleDetails/props.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import type {
3333
ToggleDetailsTheme
3434
} from '@instructure/shared-types'
3535
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
36+
import type { ViewProps } from '@instructure/ui-view'
3637

3738
type ToggleDetailsOwnProps = {
3839
variant?: 'default' | 'filled'
@@ -48,7 +49,10 @@ type ToggleDetailsOwnProps = {
4849
* Whether the content is initially expanded or hidden (uncontrolled)
4950
*/
5051
defaultExpanded?: boolean
51-
onToggle?: (event: React.MouseEvent, expanded: boolean) => void
52+
onToggle?: (
53+
event: React.KeyboardEvent<ViewProps> | React.MouseEvent<ViewProps>,
54+
expanded: boolean
55+
) => void
5256
/**
5357
* The icon to display next to the summary text when content is hidden
5458
*/

scripts/bootstrap.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,12 @@ function buildProject() {
3434
// if one of the sub processes fails, then we terminate the other sub process and exit the main process
3535
const spawnStdIoOpts = { stdio: ['inherit', 'inherit', 'pipe'] }
3636
execSync(
37-
'lerna run prepare-build --stream --scope @instructure/ui-icons',
37+
'lerna run prepare-build --scope @instructure/ui-icons --loglevel silent',
3838
opts
3939
)
4040
// eslint-disable-next-line no-console
4141
console.info('Starting Babel and TSC...')
42-
const tsBuild = spawn(
43-
'npm',
44-
['run', 'build:types', '--verbose'],
45-
spawnStdIoOpts
46-
)
42+
const tsBuild = spawn('npm', ['run', 'build:types'], spawnStdIoOpts)
4743
const babelBuild = spawn('npm', ['run', 'build'], spawnStdIoOpts)
4844
tsBuild.on('exit', (code) => {
4945
if (code !== 0) {
@@ -64,9 +60,7 @@ function buildProject() {
6460
console.error("'npm run build' failed :(")
6561
process.exit(code)
6662
}
67-
const result = execSync('npm run build:tokens', opts)
68-
// eslint-disable-next-line no-console
69-
console.info('npm run build:tokens result', result)
63+
execSync('npm run build:tokens', opts)
7064
})
7165
}
7266
function bootstrap() {

0 commit comments

Comments
 (0)