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

TypeScript Rollout Tier 9 - Colorpicker & color #374

Merged
merged 6 commits into from
Jan 12, 2025

Conversation

kikuomax
Copy link
Collaborator

Related issues:

Proposed Changes

  • Migration of utils/color
    • This has to be tied to the colorpicker migration, otherwise, we will get a weird build error.
  • Migration of colorpicker
    • packages/buefy-next/rollup.config.mjs will likely cause a conflict after merging the other PRs in this tier.

Rewrites `src/utils/color.js` in TypeScript.

Unrolls the loops to dynamically define the following Color components
as pairs of `get` and `set` methods:
- `red`
- `green`
- `blue`
- `alpha`
- `hue`
- `saturation`
- `lightness`

My attempt to augment the `Color` class with an ambient module did not
work when all the Buefy types were bundled in a single `.dts` file;
i.e., it won't work in users' environments.

Replaces `get [Symbol.toString]` with `get [Symbol.toStringTag]` to
suppress a type error, although, I am not 100% confident about this
solutation because I was not able to identify the intention of the
original code.

`color.ts` exports color model types: `Hsl`, `Hsla`, `Rgb`, and `Rgba`
Rewrites `src/utils/color.spec.js→ts` in TypeScript. Imports the spec
building blocks from the `vitest` package.
Rewrites the colorpicker components in the `src/components/colorpicker`
in TypeScript.

In `Colorpicker.vue`:
- The `modelValue` prop, and its emitted value on "update:modelValue"
  have different types; `string | Rgb` vs `Color`. A user of
  `Colorpicker` may specify a string or an `Rgb` object to the prop
  unless `v-model` is necessary.
- Introduces a new type `IColorpicker` which represents a partial
  interface of `Colorpicker` to avoid circular references between
  `Colorpicker`, and `ColorFormatter` or `ColorParser`
- Introduces new types:
  - `ColorFormatter`: type of the `colorFormatter` prop
  - `ColorParser`: type of the `colorParser` prop
- No longer imports `Icon` and `Select`, because they are not used
- I found the following methods were not used but decided to leave them
  until we come back to deal with the `open-on-focus` and
  `close-on-click` props:
  - `handleOnFocus`
  - `toggle`: commented out because it contains an unfixable type error
  - `onInputClick`
  - `keyPress`
  - `togglePicker`: only called in `handleOnFocus` and `keyPress`

In `ColorpickerHSLRepresentationSquare.vue`, fixes a bug that the
`precision` custom template literal function tried to round `values`
instead of `values[i]`, while fixing the type error

In `ColorpickerHSLRepresentationSquare/Triangle.vue, the `value` prop,
and its emitted value on "input" have different types; `Hsl` vs `Color`

In `Colorpicker.vue`, and `ColorpickerAlphaSlider.vue`:
- Directly names Buefy components when they are registered so that they
  are type-checked. Note no type-checking is performed for components
  indirectly registered using the `name` field.

Replaces JSDoc-style comments with ordinary ones so that
`@microsoft/api-extractor` won't pick them up for documentation.
Rewrites the specs for the colorpicker components in the
`src/components/colorpicker` folder in TypeScript.

All the changes are straightforward. Imports the spec building blocks
from the `vitest` package.

In the `__snapshots__` folder, replaces the snapshots produced by Jest
with those by Vitest.
`rollup.config.mjs` removes "colorpicker" from `JS_COMPONENTS`.
Rewrites the documentation for the colorpicker components in the
`src/pages/components/colorpicker` folder in TypeScript. All the changes
are straightforward.

Here is a TypeScript migration tip:
- Explicitly import and register components so that they are type
  checked. No type-checking is performed for globally registered
  components.
@kikuomax kikuomax requested a review from wesdevpro January 12, 2025 04:50
@kikuomax kikuomax merged commit 8308232 into ntohq:dev Jan 12, 2025
18 checks passed
@kikuomax kikuomax deleted the ts-rollout-tier-9-colorpicker branch January 12, 2025 15:07
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.

2 participants