Skip to content

Commit 8323d91

Browse files
committed
fix(ui-toggle-details,ui-expandable): improve typing for onClick prop
1 parent 0d32bd0 commit 8323d91

File tree

12 files changed

+42
-52
lines changed

12 files changed

+42
-52
lines changed

lerna.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"version": "10.21.0",
33
"npmClient": "npm",
4+
"loglevel": "warn",
45
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
5-
}
6+
}

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@
2121
"cy:component": "cypress run --component",
2222
"test:vitest": "vitest --watch=false",
2323
"test:vitest-watch": "vitest",
24-
"lint": "lerna run lint --stream",
24+
"lint": "lerna run lint",
2525
"lint:changes": "npm run lint -- --since HEAD^",
26-
"lint:fix": "lerna run lint:fix --stream",
26+
"lint:fix": "lerna run lint:fix",
2727
"lint:commits": "commitlint --from=HEAD^1",
28-
"bootstrap": "node scripts/bootstrap.js",
29-
"build": "lerna run build --stream",
30-
"build:watch": "lerna run build:watch --stream",
31-
"build:docs": "lerna run bundle --stream --scope docs-app",
28+
"bootstrap": "time node scripts/bootstrap.js",
29+
"build": "lerna run build",
30+
"build:watch": "lerna run build:watch",
31+
"build:docs": "lerna run bundle --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 --scope @instructure/ui-icons && npm run build:types",
3535
"clean": "node scripts/clean.js",
3636
"clean-node": "node scripts/clean.js --nuke_node",
37-
"export:icons": "lerna run export --stream --scope @instructure/ui-icons",
37+
"export:icons": "lerna run export --scope @instructure/ui-icons",
3838
"bump": "ui-scripts bump",
3939
"release": "ui-scripts publish",
4040
"husky:pre-commit": "lint-staged && node scripts/checkTSReferences.js",
4141
"postinstall": "husky",
42-
"ts:check": "lerna run ts:check --stream"
42+
"ts:check": "lerna run ts:check"
4343
},
4444
"license": "MIT",
4545
"resolutions": {

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@ class ToggleDetails extends Component<ToggleDetailsProps> {
168168
return <div css={this.props.styles?.content}>{this.props.children}</div>
169169
}
170170

171-
handleToggle = (event: React.MouseEvent, expanded: boolean) => {
171+
handleToggle = (
172+
event: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>,
173+
expanded: boolean
174+
) => {
172175
if (typeof this.props.onToggle === 'function') {
173176
this.props.onToggle(event, expanded)
174177
}

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() {

scripts/clean.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,3 @@ if (args.length > 0 && args[0] === '--nuke_node') {
9292
console.info('Deleting node_modules recursively...')
9393
removeNodeModules()
9494
}
95-
96-
// eslint-disable-next-line no-console
97-
console.info('clean finished')

0 commit comments

Comments
 (0)