Skip to content

Commit

Permalink
chore: expose DataAttributes type
Browse files Browse the repository at this point in the history
  • Loading branch information
quantizor committed Sep 13, 2023
1 parent af178ea commit 5a41553
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/styled-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {
CSSProp,
CSSProperties,
CSSPseudos,
DataAttributes,
DefaultTheme,
ExecutionContext,
ExecutionProps,
Expand Down
13 changes: 13 additions & 0 deletions packages/styled-components/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ export interface StyledOptions<R extends Runtime, Props extends object> {

export type Dict<T = any> = { [key: string]: T };

/**
* This type is intended for when data attributes are composed via
* the `.attrs` API:
*
* ```tsx
* styled.div.attrs<DataAttributes>({ 'data-testid': 'foo' })``
* ```
*
* Would love to figure out how to support this natively without having to
* manually compose the type, but haven't figured out a way to do so yet that
* doesn't cause specificity loss (see `test/types.tsx` if you attempt to embed
* `DataAttributes` directly in the `Attrs<>` type.)
*/
export type DataAttributes = { [key: `data-${string}`]: any };

export type ExecutionProps = {
Expand Down

0 comments on commit 5a41553

Please sign in to comment.