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: Add NumericControl #27

Merged
merged 13 commits into from
Mar 13, 2024
Merged

feat: Add NumericControl #27

merged 13 commits into from
Mar 13, 2024

Conversation

NathanFarmer
Copy link
Contributor

@NathanFarmer NathanFarmer commented Mar 8, 2024

  • Add InputNumber renderer
  • Add NumericControl
  • Add NumericControl tests
  • Add tester
  • Add NumericControl stories

@NathanFarmer NathanFarmer self-assigned this Mar 8, 2024
src/antd/InputNumber.tsx Outdated Show resolved Hide resolved
const value = props.data === undefined || isDataEmptyObj ? defaultValue : props.data as number

const numberType = schema.type
const isInteger = (typeof numberType === "string" && numberType === "integer") || (Array.isArray(numberType) && numberType.includes("integer"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a test case for the Array.isArray(numberType) bit?

Copy link
Contributor Author

@NathanFarmer NathanFarmer Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added a missing test that asserts that numbers get rounded on input for integer. I tested schemas with type: "integer" and type: ["integer"]. I decided that type arrays with more types than "integer" will cause this variable to get set to false.

}
}

const addonAfter = props.uischema.options?.addonAfter as string | undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this cast still necessary?

Copy link
Contributor Author

@NathanFarmer NathanFarmer Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's considered an any until I do this cast. It's essentially the same as what we decided to do here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a new type InputNumberOptions to ui-schema.ts to precisely follow the pattern established by AlertControl. There is still a cast here though, the cast is just on options now and it passes through the props types.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, it's a lot easier to read if you pull off an object and type it:

const options: Maybe<InputNumberOptions> = props.uischema.options as InputNumberOptions
const addonAfter = options?.addonAfter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, how is this different than what I did?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typos like props.uischema.options?.adonafter as string | undefined doesn't get caught but it would in my example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I don't think you've seen the updated version. This is now outdated.

src/antd/InputNumber.tsx Outdated Show resolved Hide resolved
@NathanFarmer NathanFarmer merged commit badccf0 into main Mar 13, 2024
2 of 3 checks passed
@NathanFarmer NathanFarmer deleted the f/FE-59/add-numeric-control branch March 13, 2024 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants