From 1bf6060efb91a0c7bb415f32392c74f9ad78ce89 Mon Sep 17 00:00:00 2001 From: Johan Persson Date: Fri, 9 Jan 2026 17:44:09 +0100 Subject: [PATCH] refactor(ui): update Button to use defineComponent Signed-off-by: Johan Persson --- .../ui/src/components/Button/definition.ts | 23 ++++++---- packages/ui/src/components/Button/types.ts | 42 +++++++++++-------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/packages/ui/src/components/Button/definition.ts b/packages/ui/src/components/Button/definition.ts index a017157774..9f08f8e183 100644 --- a/packages/ui/src/components/Button/definition.ts +++ b/packages/ui/src/components/Button/definition.ts @@ -14,21 +14,30 @@ * limitations under the License. */ -import type { ComponentDefinition } from '../../types'; +import { defineComponent } from '../../hooks/useDefinition'; +import styles from './Button.module.css'; /** * Component definition for Button * @public */ -export const ButtonDefinition = { +export const ButtonDefinition = defineComponent({ + styles, classNames: { root: 'bui-Button', content: 'bui-ButtonContent', spinner: 'bui-ButtonSpinner', }, - dataAttributes: { - size: ['small', 'medium', 'large'] as const, - variant: ['primary', 'secondary', 'tertiary'] as const, - loading: [true, false] as const, + surface: 'leaf', + propDefs: { + size: { dataAttribute: true, default: 'small' }, + variant: { dataAttribute: true, default: 'primary' }, + loading: { dataAttribute: true }, + iconStart: {}, + iconEnd: {}, + onSurface: {}, + children: {}, + className: {}, + style: {}, }, -} as const satisfies ComponentDefinition; +}); diff --git a/packages/ui/src/components/Button/types.ts b/packages/ui/src/components/Button/types.ts index 964b439bf6..a469eab48f 100644 --- a/packages/ui/src/components/Button/types.ts +++ b/packages/ui/src/components/Button/types.ts @@ -14,27 +14,33 @@ * limitations under the License. */ -import { Breakpoint } from '../..'; -import { ReactElement, ReactNode } from 'react'; -import { ButtonProps as RAButtonProps } from 'react-aria-components'; -import { Responsive, Surface } from '../../types'; +import type { ReactElement, ReactNode, CSSProperties } from 'react'; +import type { ButtonProps as RAButtonProps } from 'react-aria-components'; +import type { Responsive, Surface } from '../../types'; + +/** + * Button's own properties (excluding inherited React Aria props) + * + * @public + */ +export type ButtonOwnProps = { + size?: Responsive<'small' | 'medium' | 'large'>; + variant?: Responsive<'primary' | 'secondary' | 'tertiary'>; + iconStart?: ReactElement; + iconEnd?: ReactElement; + loading?: boolean; + /** Surface the button is placed on. Defaults to context surface if available */ + onSurface?: Responsive; + children?: ReactNode; + className?: string; + style?: CSSProperties; +}; /** * Properties for {@link Button} * * @public */ -export interface ButtonProps extends RAButtonProps { - size?: 'small' | 'medium' | Partial>; - variant?: - | 'primary' - | 'secondary' - | 'tertiary' - | Partial>; - iconStart?: ReactElement; - iconEnd?: ReactElement; - children?: ReactNode; - loading?: boolean; - /** Surface the button is placed on. Defaults to context surface if available */ - onSurface?: Responsive; -} +export interface ButtonProps + extends Omit, + ButtonOwnProps {}