Skip to content

Commit

Permalink
fix labelValue types, update fluent-rc tsconfig (#3948)
Browse files Browse the repository at this point in the history
* fix labelValue types, update fluent-rc tsconfig

* replace generic with function overloads

* update eslint config

* typescript project reference for fluentui-rc in playground

* update changelog
  • Loading branch information
zxbodya authored Nov 13, 2023
1 parent 5cc83d8 commit 04aab7c
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 22 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
packages/*/lib
packages/*/lib-test
packages/*/dist
packages/docs/build
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ should change the heading of the (upcoming) version to include a major version b
-->
# 5.14.1

## @rjsf/utils

- update types for `labelValue` to have more granular return types, fixing [#3946](https://github.com/rjsf-team/react-jsonschema-form/issues/3946)

## Dev / playground

- Added Fluent UI v9 (React Components) theme to playground
- Update Fluent UI v9 and playground project references
- Update eslint ignores to exclude new typescript build output folders

# 5.14.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export default function BaseInputTemplate<
id={id}
name={id}
placeholder={placeholder}
// @ts-expect-error todo: TS2322: Type 'string | false | ReactElement<any, string | JSXElementConstructor<any>> | undefined' is not assignable to type 'string | undefined'.
label={labelValue(label, hideLabel)}
autoFocus={autofocus}
required={required}
Expand Down
1 change: 0 additions & 1 deletion packages/fluent-ui/src/CheckboxWidget/CheckboxWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export default function CheckboxWidget<
<Checkbox
id={id}
name={id}
// @ts-expect-error todo: TS2322: Type 'string | false | ReactElement<any, string | JSXElementConstructor<any>> | undefined' is not assignable to type 'string | undefined'.
label={labelValue(label || undefined, hideLabel)}
disabled={disabled || readonly}
inputProps={{
Expand Down
1 change: 0 additions & 1 deletion packages/fluent-ui/src/DateWidget/DateWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export default function DateWidget<T = any, S extends StrictRJSFSchema = RJSFSch
placeholder={placeholder}
ariaLabel={translateString(TranslatableString.AriaDateLabel)}
isRequired={required}
// @ts-expect-error todo: TS2322: Type 'string | false | ReactElement<any, string | JSXElementConstructor<any>> | undefined' is not assignable to type 'string | undefined'.
label={labelValue(label, hideLabel)}
onSelectDate={_onSelectDate}
onBlur={_onBlur}
Expand Down
1 change: 0 additions & 1 deletion packages/fluent-ui/src/RadioWidget/RadioWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
onChange={_onChange}
onFocus={_onFocus}
onBlur={_onBlur}
// @ts-expect-error todo: TS2322: Type 'string | false | ReactElement<any, string | JSXElementConstructor<any>> | undefined' is not assignable to type 'string | undefined'.
label={labelValue(label, hideLabel || !label)}
required={required}
selectedKey={selectedIndex}
Expand Down
1 change: 0 additions & 1 deletion packages/fluent-ui/src/SelectWidget/SelectWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export default function SelectWidget<
return (
<Dropdown
id={id}
// @ts-expect-error todo: TS2322: Type 'string | false | ReactElement<any, string | JSXElementConstructor<any>> | undefined' is not assignable to type 'string | undefined'.
label={labelValue(label, hideLabel)}
multiSelect={multiple}
defaultSelectedKey={multiple ? undefined : selectedIndexes}
Expand Down
2 changes: 0 additions & 2 deletions packages/fluentui-rc/src/SelectWidget/SelectWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend

return (
<Field
// @ts-expect-error todo: TS2322: Type 'false' is not assignable to type 'WithSlotShorthandValue<WithSlotRenderFunction<Omit<ComponentProps<LabelSlots>, "required"> & ...
// See https://github.com/rjsf-team/react-jsonschema-form/issues/3946
label={labelValue(label, hideLabel)}
validationState={rawErrors.length ? 'error' : undefined}
required={required}
Expand Down
24 changes: 24 additions & 0 deletions packages/fluentui-rc/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "../../../tsconfig.base.json",
"include": [
"./"
],
"compilerOptions": {
"rootDir": "./",
"outDir": "../lib",
"baseUrl": "../",
"jsx": "react-jsx",
"skipLibCheck": true
},
"references": [
{
"path": "../../core"
},
{
"path": "../../utils"
},
{
"path": "../../validator-ajv8"
}
]
}
18 changes: 18 additions & 0 deletions packages/fluentui-rc/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "../../../tsconfig.base.json",
"include": ["./"],
"compilerOptions": {
"rootDir": "./",
"baseUrl": "../",
"noEmit": true,
"jsx": "react-jsx"
},
"references": [
{
"path": "../src"
},
{
"path": "../../snapshot-tests"
}
]
}
16 changes: 3 additions & 13 deletions packages/fluentui-rc/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"compilerOptions": {
"rootDir": "./src",
"outDir": "./lib",
"baseUrl": "./",
"jsx": "react-jsx",
"skipLibCheck": true
},
"files": [],
"references": [
{
"path": "../core"
"path": "./src"
},
{
"path": "../utils"
},
{
"path": "../validator-ajv8"
"path": "./test"
}
]
}
1 change: 1 addition & 0 deletions packages/playground/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
{ "path": "../chakra-ui" },
{ "path": "../core" },
{ "path": "../fluent-ui" },
{ "path": "../fluentui-rc" },
{ "path": "../material-ui" },
{ "path": "../mui" },
{ "path": "../semantic-ui" },
Expand Down
16 changes: 14 additions & 2 deletions packages/utils/src/labelValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ import { ReactElement } from 'react';
* @param [fallback] - One of 3 values, `undefined` (the default), `false` or an empty string
* @returns - `fallback` if `hideLabel` is true, otherwise `label`
*/
export function labelValue(label?: string | ReactElement, hideLabel?: boolean, fallback?: ''): undefined | string;
export default function labelValue(label?: string | ReactElement, hideLabel?: boolean, fallback?: false | '') {

export default function labelValue(label?: string, hideLabel?: boolean, fallback?: ''): undefined | string;
export default function labelValue(label?: string, hideLabel?: boolean, fallback?: false): undefined | false | string;
export default function labelValue(label?: ReactElement, hideLabel?: boolean, fallback?: ''): undefined | ReactElement;
export default function labelValue(
label?: ReactElement,
hideLabel?: boolean,
fallback?: false
): undefined | false | ReactElement;
export default function labelValue(
label?: string | ReactElement,
hideLabel?: boolean,
fallback?: false | ''
): undefined | false | string | ReactElement {
return hideLabel ? fallback : label;
}

0 comments on commit 04aab7c

Please sign in to comment.