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 type definitions for @observablehq/inputs #12

Merged
merged 30 commits into from
Jul 24, 2023

Conversation

neoncitylights
Copy link
Contributor

@neoncitylights neoncitylights commented Jun 26, 2023

Fixes #32

  • Add type definitions for date() and datetime() inputs
  • Add type definition for fileOf()
  • Add type definition for searchFilter()
  • Add type definition for textarea()
  • Use discriminated union types for OhqInputSelectOptions with multiple, size, and value properties
  • Use discriminated union types for OhqInputTextOptions with type and min/max
  • use string literal union for autocapitalize property in OhqInputTextOptions, OhqInputSearchOptions
  • use string literal union for autocomplete property in OhqInputTextOptions, OhqInputSearchOptions
  • Replace cases/usage of unknown type where possible
  • Replace cases/usage of any type where possible

 - adds unit tests for format function utils, button(), and checkbox()
 - fixes formatting functions to accept locales, and return a function that returns a string, instead of directly returning a string
 - fix OhqInputFormatFn to also accept an optional index (2nd argument) and an optional array (3rd argument)
@neoncitylights neoncitylights changed the title feat: add type declarations for @observablehq/inputs feat: add type definitions for @observablehq/inputs Jul 22, 2023
 - make types properly use generics for `OhqInputSort<T>` and `OhqInputFormatFn<T>`
 - allow button to also accept `HTMLElement` type for content
 - add method overloading for the following methods: `form()`, `button()`, and `checkbox()`, `radio()`, `select()`. This allows for accepting arrays and Map instances.
 - rename `button.test.ts` to `buttons.test.ts`
 - add unit tests for checkbox, date/datetime, form, radio, and number inputs
 - move form unit tests outside of utility unit tests
@neoncitylights
Copy link
Contributor Author

neoncitylights commented Jul 23, 2023

Instances of unknown:

  • OhqInputTextOptions.datalist
  • OhqInputSearchOptions.filter
  • OhqTableOptions.values

Instances of any:

  • OhqInputToggleOptions.value
  • OhqInputRadioOptions.value
  • OhqInputSearchOptions.datalist

Other fixes:
 - `OhqInputSearchOptions<T>`
  - fixes `query` property to only be a `string` instead of `string|string[]`
  - fixes `filter` property to not be unknown anymore, to match function signature of `searchFilter<T>()`
 - `OhqInputTableOptions<T>`: fixes `header` property, where the key value itself can either be a `string` or `HTMLElement`
This adds higher-level support to the `multiple` property. Some other property types change or are only accessible based on the value of the `multiple` property. For example:
 - It is only possible to set `size` as a number if `multiple` is true
 - It is only possible to set `value` as an array of strings if `multiple` is true or a number
 - `OhqInputToggleOptions<T>`: Fix `values` property to only accept a 2-tuple of the same type
 - `OhqInputRadioOptions<T>`: Fix any usage in `value` property
 - `OhqInputSearchOptions<T>`: Fix any usage in `datalist` property
 - `OhqTableOptions<T>`: Fix unknown usage in `value` property
 - `OhqInputTextOptions`: Fix unknown usage in `datalist` property
Type fix for `OhqInputTextOptions<T>` - now can only use a certain data type for `min`/`max` depending of the `type` value.
WOOHOO, last on the checklist
@neoncitylights neoncitylights merged commit 05c5e49 into main Jul 24, 2023
6 checks passed
@neoncitylights neoncitylights deleted the types-inputs branch July 24, 2023 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Stabilize type definitions for @observablehq/inputs
1 participant