Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TypeScript): upgrade internal TypeScript version with a few alignments #3350

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/dnb-design-system-portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"stylelint-config-recommended": "12.0.0",
"stylelint-config-standard-scss": "9.0.0",
"svg-react-loader": "0.4.6",
"typescript": "5.0.4",
"typescript": "5.2.2",
"unist-util-visit": "^2"
},
"buildVersion": "[LOCAL BUILD]",
Expand Down
2 changes: 1 addition & 1 deletion packages/dnb-eufemia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
"svgo": "3.0.0",
"tar": "6.1.11",
"traverse": "0.6.6",
"typescript": "5.0.4",
"typescript": "5.2.2",
"vd-tool": "4.0.2",
"wait-on": "6.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/dnb-eufemia/src/components/input/Input.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default class Input extends React.Component<InputProps, any> {
render(): JSX.Element;
}
export interface SubmitButtonProps
extends React.HTMLProps<HTMLInputElement> {
extends React.HTMLProps<HTMLButtonElement> {
id?: string;
/**
* The content value of the input.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ describe('Field.Number', () => {

it('renders autoComplete', () => {
const { rerender } = render(
<Field.Number autoComplete="postalCode" />
<Field.Number autoComplete="postal-code" />
)
expect(
document.querySelector('input').getAttribute('autocomplete')
).toBe('postalCode')
).toBe('postal-code')

rerender(<Field.Number path="/postalCode" autoComplete="tel" />)
expect(document.querySelector('input').getAttribute('name')).toBe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ describe('Field.String', () => {

it('renders autoComplete', () => {
const { rerender } = render(
<Field.String autoComplete="firstName" />
<Field.String autoComplete="given-name" />
)
expect(
document.querySelector('input').getAttribute('autocomplete')
).toBe('firstName')
).toBe('given-name')

rerender(
<Field.String path="/firstName" autoComplete="family-name" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ import NumberFormat, {
NumberFormatProps,
} from '../../../../components/NumberFormat'
import {
ToCamelCase,
IncludeCamelCase,
convertCamelCaseProps,
} from '../../../../shared/helpers/withCamelCaseProps'

export type Props = ValueProps<number> & ToCamelCase<NumberFormatProps>
export type Props = ValueProps<number> &
IncludeCamelCase<NumberFormatProps>

function NumberValue(props: Props) {
const { className, label, placeholder, inline, showEmpty, ...rest } =
useDataValue(props)

const numberFormatProps = convertCamelCaseProps(
omitSpacingProps(omitDataValueProps(rest)) as NumberFormatProps
omitDataValueProps(omitSpacingProps(rest))
)

return (
Expand Down
30 changes: 11 additions & 19 deletions packages/dnb-eufemia/src/extensions/forms/hooks/useDataValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import useId from './useId'
export default function useDataValue<
Value = unknown,
Props extends FieldProps<Value> = FieldProps<Value>,
>(props: Props): Props & ReturnAdditional<Value> {
>(props: Props): Props & FieldProps<Value> & ReturnAdditional<Value> {
const {
path,
itemPath,
Expand Down Expand Up @@ -675,11 +675,13 @@ export default function useDataValue<
warning: !inFieldBlock ? warning : undefined,
error: !inFieldBlock ? error : undefined,
hasError,
isChanged: changedRef.current,
disabled,
autoComplete:
props.autoComplete ??
(dataContext.autoComplete === true ? 'on' : 'off'),
disabled,

// Return additional hook related props (ReturnAdditional)
isChanged: changedRef.current,
ariaAttributes,
dataContext,
setHasFocus,
Expand All @@ -692,29 +694,21 @@ export default function useDataValue<
}

interface ReturnAdditional<Value> {
id: string
name: string
value: Value
error: FieldProps<unknown>['error']
warning: FieldProps<unknown>['warning']
info: FieldProps<unknown>['info']
autoComplete: HTMLInputElement['autocomplete']
disabled: boolean
hasError: boolean
isChanged: boolean
dataContext: ContextState
ariaAttributes: AriaAttributes
dataContext: ContextState
setHasFocus: (hasFocus: boolean, valueOverride?: unknown) => void
handleFocus: () => void
handleBlur: () => void
handleChange: FieldProps<unknown>['onChange']
handleChange: FieldProps<Value>['onChange']
updateValue: (value: Value) => void
forceUpdate: () => void
}

export function omitDataValueProps<
OmittedProps extends ReturnAdditional<unknown>,
>(props: OmittedProps) {
Props extends FieldProps<unknown> & ReturnAdditional<unknown>,
>(props: Props) {
// Do not include typical HTML attributes
const {
name, // eslint-disable-line
Expand All @@ -734,8 +728,6 @@ export function omitDataValueProps<
forceUpdate, // eslint-disable-line
...restProps
} = props
return Object.freeze(restProps) as Omit<
OmittedProps,
keyof ReturnAdditional<unknown>
>

return restProps
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ export function classWithCamelCaseProps<
return Derived
}

/**
* Converts camel case props to snake case props.
*
* @template P - The type of the props object.
* @param {P} props - The props object to convert.
* @returns {P} - The converted props object.
*/
export function convertCamelCaseProps<P>(props: P) {
const isFrozen = Object.isFrozen(props)
const newProps = isFrozen ? { ...props } : props
Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3551,7 +3551,7 @@ __metadata:
svgo: "npm:3.0.0"
tar: "npm:6.1.11"
traverse: "npm:0.6.6"
typescript: "npm:5.0.4"
typescript: "npm:5.2.2"
vd-tool: "npm:4.0.2"
wait-on: "npm:6.0.0"
what-input: "npm:5.2.10"
Expand Down Expand Up @@ -14059,7 +14059,7 @@ __metadata:
stylelint-config-recommended: "npm:12.0.0"
stylelint-config-standard-scss: "npm:9.0.0"
svg-react-loader: "npm:0.4.6"
typescript: "npm:5.0.4"
typescript: "npm:5.2.2"
unist-util-visit: "npm:^2"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -33388,23 +33388,23 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:5.0.4":
version: 5.0.4
resolution: "typescript@npm:5.0.4"
"typescript@npm:5.2.2":
version: 5.2.2
resolution: "typescript@npm:5.2.2"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: e5c3adff09a138c0e27d13b5bb2b106ca17a162ffa945d66161669c265c65436309c5817358a2af1abb69d07440d358f8c1ed7cbb63a2c8680e19b9c268fe4ef
checksum: d65e50eb849bd21ff8677e5b9447f9c6e74777e346afd67754934264dcbf4bd59e7d2473f6062d9a015d66bd573311166357e3eb07fea0b52859cf9bb2b58555
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A5.0.4#optional!builtin<compat/typescript>":
version: 5.0.4
resolution: "typescript@patch:typescript@npm%3A5.0.4#optional!builtin<compat/typescript>::version=5.0.4&hash=b5f058"
"typescript@patch:typescript@npm%3A5.2.2#optional!builtin<compat/typescript>":
version: 5.2.2
resolution: "typescript@patch:typescript@npm%3A5.2.2#optional!builtin<compat/typescript>::version=5.2.2&hash=f3b441"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: b1b62606c7ec75efe9edc61e195d9e69f0440cac1bcd111dfa864f839255f0d9a7b79869f2823559c608826fc0c9894d2917ae4063e0aa06f5d0784a35170497
checksum: f79cc2ba802c94c2b78dbb00d767a10adb67368ae764709737dc277273ec148aa4558033a03ce901406b35fddf4eac46dabc94a1e1d12d2587e2b9cfe5707b4a
languageName: node
linkType: hard

Expand Down
Loading