Skip to content

Commit

Permalink
Try: Add CSS Custom Properties to CSS types (WordPress#61872)
Browse files Browse the repository at this point in the history
* Augment module.

* Add changelog entry.

Co-authored-by: DaniGuardiola <[email protected]>
Co-authored-by: mirka <[email protected]>
  • Loading branch information
3 people authored and carstingaxion committed Jun 4, 2024
1 parent e558afe commit b2487bd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Internal

- Add type support for CSS Custom Properties ([#61872](https://github.com/WordPress/gutenberg/pull/61872)).
- Remove usage of deprecated spreading of `key` prop in JSX in CustomSelectControl and FormTokenField components ([#61692](https://github.com/WordPress/gutenberg/pull/61692)).
- Tooltip: Fix Ariakit tooltip store usage ([#61858](https://github.com/WordPress/gutenberg/pull/61858)).

Expand Down
13 changes: 5 additions & 8 deletions packages/components/src/color-palette/stories/index.story.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import type { CSSProperties } from 'react';
import type { Meta, StoryFn } from '@storybook/react';

/**
Expand Down Expand Up @@ -92,13 +91,11 @@ MultipleOrigins.args = {
export const CSSVariables: StoryFn< typeof ColorPalette > = ( args ) => {
return (
<div
style={
{
'--red': '#f00',
'--yellow': '#ff0',
'--blue': '#00f',
} as CSSProperties
}
style={ {
'--red': '#f00',
'--yellow': '#ff0',
'--blue': '#00f',
} }
>
<Template { ...args } />
</div>
Expand Down
9 changes: 9 additions & 0 deletions packages/components/src/css.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type * as CSS from 'csstype';

// See: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/f6d4d15522356eba4a0267142834e3abc6b603fc/types/react/index.d.ts#L2580-L2587
declare module 'csstype' {
interface Properties {
// Allow any CSS Custom Properties
[ index: `--${ string }` ]: any;
}
}
14 changes: 6 additions & 8 deletions packages/components/src/progress-bar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import type { CSSProperties, ForwardedRef } from 'react';
import type { ForwardedRef } from 'react';

/**
* WordPress dependencies
Expand All @@ -26,13 +26,11 @@ function UnforwardedProgressBar(
return (
<ProgressBarStyled.Track className={ className }>
<ProgressBarStyled.Indicator
style={
{
'--indicator-width': ! isIndeterminate
? `${ value }%`
: undefined,
} as CSSProperties
}
style={ {
'--indicator-width': ! isIndeterminate
? `${ value }%`
: undefined,
} }
isIndeterminate={ isIndeterminate }
/>
<ProgressBarStyled.ProgressElement
Expand Down

0 comments on commit b2487bd

Please sign in to comment.