Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/components/Button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ import { MdPlayArrow } from 'react-icons/md';
<BBButton layout="stacked" icon={<MdPlayArrow size={30} />} label="Settings" onClick={() => (console.log('clicked'))}/>
```

### Submit Button

`BBButton` renders `type="button"` by default, so it never submits an enclosing `<form>`. Pass `type="submit"` to opt in:

```jsx
import { BBButton } from 'bbb-ui-components-react';

<form onSubmit={handleSubmit}>
<BBButton type="submit" label="Save" onClick={() => (console.log('clicked'))}/>
</form>
```

## Props

| Property | Type | Default | Description |
Expand All @@ -69,6 +81,7 @@ import { MdPlayArrow } from 'react-icons/md';
| `variant` | `keyof typeof VARIANTS` | `'primary'` | The variant of the button. |
| `size` | `keyof typeof SIZES` | `'medium'` | The size of the button. |
| `layout` | `keyof typeof LAYOUTS` | `'default'` | The layout of the button. |
| `type` | `'button' \| 'submit' \| 'reset'` | `'button'` | The native `type` attribute of the `<button>`. Defaults to `'button'` so it never submits an enclosing form unless `'submit'` is passed explicitly. |
| `disabled` | `boolean` | `false` | If `true`, the button will be disabled. |
| `children` | `React.ReactNode` | | The content of the button, typically used for the 'default' layout. |
| `icon` | `React.ReactNode` | | The icon to be displayed. Used for 'circle', 'squared' and 'stacked' layouts. |
Expand Down
8 changes: 8 additions & 0 deletions src/components/Button/component.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
DEFAULT_VARIANT,
DEFAULT_SIZE,
DEFAULT_LAYOUT,
TYPE_VALUES,
DEFAULT_TYPE,
} from './constants';

const meta = {
Expand Down Expand Up @@ -64,6 +66,12 @@ const meta = {
description: `Layout mode for the button. Allowed values: ${LAYOUT_VALUES.join(', ')}. Some props are layout-specific (see icon, iconStart/iconEnd, helperIcon).`,
table: { defaultValue: { summary: `${DEFAULT_LAYOUT}` } },
},
type: {
control: 'select',
options: TYPE_VALUES,
description: `Native \`type\` attribute of the underlying \`<button>\`. Allowed values: ${TYPE_VALUES.join(', ')}. Defaults to \`button\` so it never submits an enclosing form unless \`submit\` is passed explicitly.`,
table: { defaultValue: { summary: `${DEFAULT_TYPE}` } },
},
disabled: {
control: 'boolean',
description: 'Disables interaction and applies disabled visuals. Works across all layouts.',
Expand Down
5 changes: 5 additions & 0 deletions src/components/Button/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
DEFAULT_LAYOUT,
LAYOUTS,
DEFAULT_TOOLTIP_PLACEMENT,
DEFAULT_TYPE,
} from './constants';
import * as Styled from './styles';
import Tippy from '@tippyjs/react';
Expand Down Expand Up @@ -39,6 +40,7 @@ function Button(props: ButtonProps): JSX.Element {
variant = DEFAULT_VARIANT,
size = DEFAULT_SIZE,
layout = DEFAULT_LAYOUT,
type = DEFAULT_TYPE,
disabled = false,
children,
showFeedback = false,
Expand Down Expand Up @@ -93,6 +95,7 @@ function Button(props: ButtonProps): JSX.Element {
return (
<Styled.Button
id={id}
type={type}
data-test={testId}
onClick={handleClick}
onKeyDown={onKeyDown}
Expand Down Expand Up @@ -125,6 +128,7 @@ function Button(props: ButtonProps): JSX.Element {
<Styled.ButtonWrapper data-test={testId} $layout={layout}>
<Styled.Button
id={id}
type={type}
onClick={handleClick}
onKeyDown={onKeyDown}
{...accessibilityProps}
Expand Down Expand Up @@ -174,6 +178,7 @@ function Button(props: ButtonProps): JSX.Element {
return (
<Styled.Button
id={id}
type={type}
data-test={testId}
onClick={handleClick}
onKeyDown={onKeyDown}
Expand Down
11 changes: 11 additions & 0 deletions src/components/Button/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ const TOOLTIP_PLACEMENTS = {
const TOOLTIP_PLACEMENT_VALUES = Object.values(TOOLTIP_PLACEMENTS);
const DEFAULT_TOOLTIP_PLACEMENT = TOOLTIP_PLACEMENTS.TOP;

const TYPES = {
BUTTON: 'button',
SUBMIT: 'submit',
RESET: 'reset',
} as const;
const TYPE_VALUES = Object.values(TYPES);
const DEFAULT_TYPE = TYPES.BUTTON;

const CSS_COLOR_PROPERTIES: CSSColorPropertiesType = {
primary: {
default: {
Expand Down Expand Up @@ -219,6 +227,9 @@ export {
TOOLTIP_PLACEMENTS,
TOOLTIP_PLACEMENT_VALUES,
DEFAULT_TOOLTIP_PLACEMENT,
TYPES,
TYPE_VALUES,
DEFAULT_TYPE,
CSS_COLOR_PROPERTIES,
CSS_COLOR_PROPERTIES_DISABLED,
CSS_SIZE_PROPERTIES,
Expand Down
5 changes: 5 additions & 0 deletions src/components/Button/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
VARIANT_VALUES,
LAYOUTS,
TOOLTIP_PLACEMENT_VALUES,
TYPE_VALUES,
} from './constants';

export type EssentialColorProperties = {
Expand Down Expand Up @@ -42,6 +43,7 @@ type ColorType = typeof COLOR_VALUES[number];
type SizeType = typeof SIZE_VALUES[number];
type LayoutType = typeof LAYOUT_VALUES[number];
type TooltipPlacementType = typeof TOOLTIP_PLACEMENT_VALUES[number];
type ButtonType = typeof TYPE_VALUES[number];

export interface StyledHelperIconContainer {
$hover: boolean;
Expand Down Expand Up @@ -101,6 +103,9 @@ type BaseButtonProps = {
/** Button size; affects padding and, for the `circle`/`squared` layouts, the overall box size (both render at the same size). @default 'md' */
size?: SizeType;

/** Native `type` attribute of the `<button>`; defaults to `'button'` so it never submits an enclosing form unless `'submit'` is passed explicitly. @default 'button' */
type?: ButtonType;

/** Disables interaction and applies disabled styling. @default false */
disabled?: boolean;

Expand Down
Loading