@bootsmonday/corncob-design-language-react 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/.changelog/README.md +33 -0
  2. package/CHANGELOG.md +9 -0
  3. package/jest.config.cjs +17 -0
  4. package/jest.setup.cjs +19 -0
  5. package/package.json +34 -4
  6. package/src/common/choice-name.js +11 -0
  7. package/src/common/choice-name.test.js +46 -0
  8. package/src/common/field.jsx +16 -0
  9. package/src/common/field.test.js +33 -0
  10. package/src/common/form-item.jsx +9 -0
  11. package/src/common/form-item.test.js +45 -0
  12. package/src/components/badges/badge.jsx +11 -0
  13. package/src/components/badges/badge.stickersheet.jsx +39 -0
  14. package/src/components/badges/badge.test.js +69 -0
  15. package/src/components/button-bars/button-bar.jsx +10 -0
  16. package/src/components/button-bars/button-bar.stickersheet.jsx +86 -0
  17. package/src/components/button-bars/button-bar.test.js +58 -0
  18. package/src/components/buttons/button.jsx +15 -0
  19. package/src/components/buttons/button.stickersheet.jsx +204 -0
  20. package/src/components/buttons/button.test.js +84 -0
  21. package/src/components/checkboxes/checkbox-group.jsx +13 -0
  22. package/src/components/checkboxes/checkbox.jsx +41 -0
  23. package/src/components/checkboxes/checkbox.stickersheet.jsx +53 -0
  24. package/src/components/checkboxes/checkbox.test.js +154 -0
  25. package/src/components/expandables/expandable.jsx +36 -0
  26. package/src/components/expandables/expandable.stickersheet.jsx +100 -0
  27. package/src/components/expandables/expandable.test.js +125 -0
  28. package/src/components/footers/footer.jsx +50 -0
  29. package/src/components/footers/footer.stickersheet.jsx +77 -0
  30. package/src/components/footers/footer.test.js +64 -0
  31. package/src/components/headers/header.jsx +57 -0
  32. package/src/components/headers/header.stickersheet.jsx +63 -0
  33. package/src/components/headers/header.test.js +63 -0
  34. package/src/components/links/link.jsx +17 -0
  35. package/src/components/links/link.stickersheet.jsx +75 -0
  36. package/src/components/links/link.test.js +70 -0
  37. package/src/components/messages/message.jsx +33 -0
  38. package/src/components/messages/message.stickersheet.jsx +96 -0
  39. package/src/components/messages/message.test.js +92 -0
  40. package/src/components/modals/modal.jsx +25 -0
  41. package/src/components/modals/modal.stickersheet.jsx +44 -0
  42. package/src/components/modals/modal.test.js +32 -0
  43. package/src/components/panel-menus/panel-menu.jsx +25 -0
  44. package/src/components/panel-menus/panel-menu.stickersheet.jsx +34 -0
  45. package/src/components/panel-menus/panel-menu.test.js +98 -0
  46. package/src/components/panels/panel.jsx +9 -0
  47. package/src/components/panels/panel.stickersheet.jsx +13 -0
  48. package/src/components/panels/panel.test.js +54 -0
  49. package/src/components/popovers/popover.jsx +49 -0
  50. package/src/components/popovers/popover.stickersheet.jsx +236 -0
  51. package/src/components/popovers/popover.test.js +98 -0
  52. package/src/components/radio-buttons/radio-button-group.jsx +13 -0
  53. package/src/components/radio-buttons/radio-button.jsx +28 -0
  54. package/src/components/radio-buttons/radio-button.stickersheet.jsx +40 -0
  55. package/src/components/radio-buttons/radio-button.test.js +119 -0
  56. package/src/components/selects/select.jsx +38 -0
  57. package/src/components/selects/select.stickersheet.jsx +34 -0
  58. package/src/components/selects/select.test.js +119 -0
  59. package/src/components/sliders/slider.jsx +42 -0
  60. package/src/components/sliders/slider.stickersheet.jsx +29 -0
  61. package/src/components/sliders/slider.test.js +81 -0
  62. package/src/components/text-inputs/text-input.jsx +28 -0
  63. package/src/components/text-inputs/text-input.stickersheet.jsx +41 -0
  64. package/src/components/text-inputs/text-input.test.js +83 -0
  65. package/src/components/toasts/toast.jsx +10 -0
  66. package/src/components/toasts/toast.stickersheet.jsx +54 -0
  67. package/src/components/toasts/toast.test.js +50 -0
  68. package/src/components/toggles/toggle.jsx +41 -0
  69. package/src/components/toggles/toggle.stickersheet.jsx +81 -0
  70. package/src/components/toggles/toggle.test.js +165 -0
  71. package/src/components/tooltips/tooltip.jsx +12 -0
  72. package/src/components/tooltips/tooltip.stickersheet.jsx +34 -0
  73. package/src/components/tooltips/tooltip.test.js +60 -0
  74. package/src/custom-elements.js +6 -0
  75. package/src/index.js +27 -0
  76. package/src/stickersheets/badges.html +31 -0
  77. package/src/stickersheets/button-bars.html +29 -0
  78. package/src/stickersheets/buttons-standard.html +33 -0
  79. package/src/stickersheets/checkboxes.html +32 -0
  80. package/src/stickersheets/expandables.html +29 -0
  81. package/src/stickersheets/footers.html +29 -0
  82. package/src/stickersheets/headers.html +29 -0
  83. package/src/stickersheets/index.html +56 -0
  84. package/src/stickersheets/links.html +29 -0
  85. package/src/stickersheets/messages.html +29 -0
  86. package/src/stickersheets/modals.html +29 -0
  87. package/src/stickersheets/panel-menus.html +29 -0
  88. package/src/stickersheets/panels.html +29 -0
  89. package/src/stickersheets/popovers.html +29 -0
  90. package/src/stickersheets/radio-buttons.html +32 -0
  91. package/src/stickersheets/select.html +31 -0
  92. package/src/stickersheets/sliders.html +31 -0
  93. package/src/stickersheets/src/stickersheet-controls.html +13 -0
  94. package/src/stickersheets/src/stickersheet-header.html +17 -0
  95. package/src/stickersheets/src/stickersheet-react-header.html +17 -0
  96. package/src/stickersheets/src/stickersheet.css +17 -0
  97. package/src/stickersheets/src/stickersheet.js +80 -0
  98. package/src/stickersheets/text-inputs.html +31 -0
  99. package/src/stickersheets/toasts.html +29 -0
  100. package/src/stickersheets/toggles.html +32 -0
  101. package/src/stickersheets/tooltips.html +29 -0
  102. package/src/utils/assign-ref.js +19 -0
  103. package/src/utils/assign-ref.test.js +35 -0
  104. package/src/utils/class-names.js +9 -0
  105. package/src/utils/class-names.test.js +21 -0
  106. package/README.md +0 -3
@@ -0,0 +1,33 @@
1
+ # React Changelog Fragments
2
+
3
+ Add one fragment file per pull request that changes product behavior.
4
+
5
+ File naming convention:
6
+
7
+ - `YYYY-MM-DD-short-topic.md`
8
+ - Example: `2026-04-13-link-list.md`
9
+
10
+ Fragment format:
11
+
12
+ ```md
13
+ ---
14
+ type: Added
15
+ scope: links
16
+ ---
17
+
18
+ Added support for `corn-link-list` styles and documentation examples.
19
+ ```
20
+
21
+ Allowed `type` values:
22
+
23
+ - `Added`
24
+ - `Changed`
25
+ - `Fixed`
26
+ - `Removed`
27
+ - `Deprecated`
28
+
29
+ Notes:
30
+
31
+ - `scope` is optional but recommended (example: `buttons`, `forms`, `docs`, `build`).
32
+ - Keep the message in plain language and user-facing.
33
+ - Multiple bullet points are allowed; they will be merged into the release section.
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## React Package Changelog
2
+
3
+ All notable changes to this package will be documented in this file.
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ Entries are generated from markdown fragments in `.changelog/` using the React release GitHub Actions workflow.
8
+
9
+ ## [Unreleased]
@@ -0,0 +1,17 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ rootDir: __dirname,
5
+ testEnvironment: '@happy-dom/jest-environment',
6
+ testMatch: ['**/?(*.)+(spec|test).[jt]s?(x)'],
7
+ transform: {
8
+ '^.+\\.[jt]sx?$': [
9
+ 'babel-jest',
10
+ { configFile: path.resolve(__dirname, '../../babel.config.js') },
11
+ ],
12
+ },
13
+ setupFilesAfterEnv: ['<rootDir>/jest.setup.cjs'],
14
+ moduleNameMapper: {
15
+ '\\.(css|less|scss|sass)$': 'identity-obj-proxy',
16
+ },
17
+ };
package/jest.setup.cjs ADDED
@@ -0,0 +1,19 @@
1
+ require('@testing-library/jest-dom');
2
+
3
+ if (!HTMLElement.prototype.attachInternals) {
4
+ Object.defineProperty(HTMLElement.prototype, 'attachInternals', {
5
+ configurable: true,
6
+ value() {
7
+ return {
8
+ setFormValue() {},
9
+ setValidity() {},
10
+ checkValidity() {
11
+ return true;
12
+ },
13
+ reportValidity() {
14
+ return true;
15
+ },
16
+ };
17
+ },
18
+ });
19
+ }
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@bootsmonday/corncob-design-language-react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "React wrappers for Corncob EDL",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "module": "src/index.js",
8
+ "exports": {
9
+ ".": "./src/index.js"
10
+ },
11
+ "sideEffects": [
12
+ "./src/custom-elements.js"
13
+ ],
14
+ "scripts": {
15
+ "build": "echo \"@bootsmonday/corncob-design-language-react has no build step\"",
16
+ "test": "jest --config ./jest.config.cjs"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/bootsmonday/corncob-design-language"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/bootsmonday/corncob-design-language/issues"
24
+ },
25
+ "homepage": "https://github.com/bootsmonday/corncob-design-language",
26
+ "peerDependencies": {
27
+ "@bootsmonday/corncob-design-language": "^0.0.1",
28
+ "react": "^19.0.0",
29
+ "react-dom": "^19.0.0"
30
+ },
31
+ "peerDependenciesMeta": {
32
+ "@bootsmonday/corncob-design-language": {
33
+ "optional": true
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,11 @@
1
+ import { Children, cloneElement, isValidElement } from 'react';
2
+
3
+ export function withChoiceName(children, name, types) {
4
+ const allowed = new Set(types);
5
+
6
+ return Children.map(children, (child) => {
7
+ if (!isValidElement(child) || !allowed.has(child.type)) return child;
8
+ if (child.props.name != null) return child;
9
+ return cloneElement(child, { name });
10
+ });
11
+ }
@@ -0,0 +1,46 @@
1
+ import { createElement } from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { withChoiceName } from './choice-name.js';
4
+
5
+ function Choice({ name, children }) {
6
+ return <input type="checkbox" name={name} aria-label={children} />;
7
+ }
8
+
9
+ function Group({ children }) {
10
+ return <fieldset>{children}</fieldset>;
11
+ }
12
+
13
+ describe('withChoiceName', () => {
14
+ test('copies name onto direct choice controls and leaves other elements alone', () => {
15
+ render(
16
+ <Group>
17
+ {withChoiceName(
18
+ [
19
+ <Choice key="one">One</Choice>,
20
+ <div key="wrap">
21
+ <Choice>Nested</Choice>
22
+ </div>,
23
+ <Choice key="keep" name="keep">
24
+ Keep
25
+ </Choice>,
26
+ ],
27
+ 'group',
28
+ [Choice]
29
+ )}
30
+ </Group>
31
+ );
32
+
33
+ expect(screen.getByRole('checkbox', { name: 'One' })).toHaveAttribute('name', 'group');
34
+ expect(screen.getByRole('checkbox', { name: 'Nested' })).not.toHaveAttribute('name');
35
+ expect(screen.getByRole('checkbox', { name: 'Keep' })).toHaveAttribute('name', 'keep');
36
+ expect(document.querySelector('div')).not.toHaveAttribute('name');
37
+ });
38
+
39
+ test('returns children unchanged when none match', () => {
40
+ const child = createElement('span', { key: 'label' }, 'Label');
41
+ const result = withChoiceName([child], 'group', [Choice]);
42
+
43
+ expect(result).toHaveLength(1);
44
+ expect(result[0].props.name).toBeUndefined();
45
+ });
46
+ });
@@ -0,0 +1,16 @@
1
+ import { joinClassNames } from '../utils/class-names.js';
2
+
3
+ export function resolveFieldLabel(label, children) {
4
+ if (label != null && label !== '') return label;
5
+ if (children != null && children !== '') return children;
6
+ return null;
7
+ }
8
+
9
+ export function fieldItemClassName(statusVariant, itemClassName = '') {
10
+ return joinClassNames(statusVariant && `corn-status--${statusVariant}`, itemClassName);
11
+ }
12
+
13
+ export function FieldStatus({ status }) {
14
+ if (status == null) return null;
15
+ return <div className="corn-status">{status}</div>;
16
+ }
@@ -0,0 +1,33 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import { FieldStatus, fieldItemClassName, resolveFieldLabel } from './field.jsx';
3
+
4
+ describe('resolveFieldLabel', () => {
5
+ test('prefers a label and falls back to children', () => {
6
+ expect(resolveFieldLabel('Name', 'Child')).toBe('Name');
7
+ expect(resolveFieldLabel(undefined, 'Child')).toBe('Child');
8
+ expect(resolveFieldLabel('', 'Child')).toBe('Child');
9
+ });
10
+
11
+ test('returns null when both are empty', () => {
12
+ expect(resolveFieldLabel(undefined, undefined)).toBeNull();
13
+ expect(resolveFieldLabel('', '')).toBeNull();
14
+ });
15
+ });
16
+
17
+ describe('fieldItemClassName', () => {
18
+ test('adds the status variant and the item class', () => {
19
+ expect(fieldItemClassName('error', 'custom-item')).toBe('corn-status--error custom-item');
20
+ expect(fieldItemClassName(undefined, '')).toBe('');
21
+ });
22
+ });
23
+
24
+ describe('FieldStatus', () => {
25
+ test('renders status text and skips an empty status', () => {
26
+ const { rerender } = render(<FieldStatus status="Required" />);
27
+
28
+ expect(screen.getByText('Required')).toHaveClass('corn-status');
29
+
30
+ rerender(<FieldStatus />);
31
+ expect(document.querySelector('.corn-status')).toBeNull();
32
+ });
33
+ });
@@ -0,0 +1,9 @@
1
+ import { joinClassNames } from '../utils/class-names.js';
2
+
3
+ export function CornFormItem({ ref, as: Component = 'div', className = '', children, ...props }) {
4
+ return (
5
+ <Component {...props} ref={ref} className={joinClassNames('corn-form--item', className)}>
6
+ {children}
7
+ </Component>
8
+ );
9
+ }
@@ -0,0 +1,45 @@
1
+ import { createRef } from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { CornFormItem } from './form-item.jsx';
4
+
5
+ describe('CornFormItem', () => {
6
+ test('renders a div with corn-form--item by default', () => {
7
+ render(<CornFormItem>Field</CornFormItem>);
8
+
9
+ const item = screen.getByText('Field');
10
+ expect(item.tagName).toBe('DIV');
11
+ expect(item).toHaveClass('corn-form--item');
12
+ });
13
+
14
+ test('renders a fieldset when as="fieldset"', () => {
15
+ render(
16
+ <CornFormItem as="fieldset">
17
+ <legend>Options</legend>
18
+ </CornFormItem>
19
+ );
20
+
21
+ const item = screen.getByRole('group', { name: 'Options' });
22
+ expect(item.tagName).toBe('FIELDSET');
23
+ expect(item).toHaveClass('corn-form--item');
24
+ });
25
+
26
+ test('merges extra className after corn-form--item', () => {
27
+ render(<CornFormItem className="corn-checkbox-group extra">Field</CornFormItem>);
28
+
29
+ expect(screen.getByText('Field')).toHaveClass('corn-form--item', 'corn-checkbox-group', 'extra');
30
+ });
31
+
32
+ test('forwards a ref to the host element', () => {
33
+ const ref = createRef();
34
+ render(<CornFormItem ref={ref}>Field</CornFormItem>);
35
+
36
+ expect(ref.current).toBe(screen.getByText('Field'));
37
+ });
38
+
39
+ test('supports a callback ref', () => {
40
+ const ref = jest.fn();
41
+ render(<CornFormItem ref={ref}>Field</CornFormItem>);
42
+
43
+ expect(ref).toHaveBeenCalledWith(screen.getByText('Field'));
44
+ });
45
+ });
@@ -0,0 +1,11 @@
1
+ import { joinClassNames, modifierClass } from '../../utils/class-names.js';
2
+
3
+ export function CornBadge({ ref, variant = 'neutral', size = 'md', className = '', children, ...props }) {
4
+ const classNames = joinClassNames('corn-badge', modifierClass('corn-badge--', variant, ['neutral']), modifierClass('corn-badge--', size, ['md']), className);
5
+
6
+ return (
7
+ <div {...props} ref={ref} className={classNames}>
8
+ {children}
9
+ </div>
10
+ );
11
+ }
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom/client';
3
+ import { CornBadge } from '../../index.js';
4
+
5
+ const BADGE_ITEMS = [
6
+ { variant: 'neutral', label: 'Neutral', icon: 'dash-lg' },
7
+ { variant: 'success', label: 'Success', icon: 'check-lg' },
8
+ { variant: 'warning', label: 'Warning', icon: 'exclamation-lg' },
9
+ { variant: 'error', label: 'Error', icon: 'x' },
10
+ { variant: 'info', label: 'Info', icon: 'info-lg' },
11
+ ];
12
+
13
+ function BadgeStatusIcon({ icon }) {
14
+ return (
15
+ <svg xmlns="http://www.w3.org/2000/svg" className="corn-icon" aria-hidden="true">
16
+ <use href={`/node_modules/bootstrap-icons/bootstrap-icons.svg#${icon}`}></use>
17
+ </svg>
18
+ );
19
+ }
20
+
21
+ function BadgeRow({ size = 'md' }) {
22
+ return BADGE_ITEMS.map(({ variant, label, icon }) => (
23
+ <CornBadge key={`${size}-${variant}`} variant={variant} size={size}>
24
+ <BadgeStatusIcon icon={icon} />
25
+ {label}
26
+ </CornBadge>
27
+ ));
28
+ }
29
+
30
+ const root = ReactDOM.createRoot(document.getElementById('test-stickersheet'));
31
+ root.render(
32
+ <div className="badges-stickersheet">
33
+ <h2>Badges</h2>
34
+ <BadgeRow />
35
+
36
+ <h2>Small Badges</h2>
37
+ <BadgeRow size="sm" />
38
+ </div>
39
+ );
@@ -0,0 +1,69 @@
1
+ import { createRef } from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { CornBadge } from './badge.jsx';
4
+
5
+ describe('CornBadge', () => {
6
+ test('renders children inside the badge', () => {
7
+ const { container } = render(<CornBadge>neutral</CornBadge>);
8
+
9
+ const badge = container.querySelector('.corn-badge');
10
+ expect(badge).toBeTruthy();
11
+ expect(badge).toHaveTextContent('neutral');
12
+ });
13
+
14
+ test('maps variant and size props to classes', () => {
15
+ render(
16
+ <CornBadge variant="success" size="sm">
17
+ success
18
+ </CornBadge>
19
+ );
20
+
21
+ expect(screen.getByText('success').closest('.corn-badge')).toHaveClass('corn-badge', 'corn-badge--success', 'corn-badge--sm');
22
+ });
23
+
24
+ test('does not add modifier classes for neutral md defaults', () => {
25
+ const { container } = render(<CornBadge>neutral</CornBadge>);
26
+
27
+ const badge = container.querySelector('.corn-badge');
28
+ expect(badge.className).toBe('corn-badge');
29
+ });
30
+
31
+ test('renders custom child content', () => {
32
+ const { container } = render(
33
+ <CornBadge>
34
+ <svg xmlns="http://www.w3.org/2000/svg" className="corn-icon" aria-hidden="true">
35
+ <use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#check-lg"></use>
36
+ </svg>
37
+ success
38
+ </CornBadge>
39
+ );
40
+
41
+ expect(container.querySelector('.corn-badge .corn-icon')).toBeTruthy();
42
+ expect(container.querySelector('.corn-badge')).toHaveTextContent('success');
43
+ });
44
+
45
+ test('forwards arbitrary props and extra className', () => {
46
+ render(
47
+ <CornBadge className="toolbar-action" data-testid="badge">
48
+ info
49
+ </CornBadge>
50
+ );
51
+
52
+ const badge = screen.getByTestId('badge');
53
+ expect(badge).toHaveClass('corn-badge', 'toolbar-action');
54
+ });
55
+
56
+ test('forwards a ref to the host element', () => {
57
+ const ref = createRef();
58
+ render(<CornBadge ref={ref}>Save</CornBadge>);
59
+
60
+ expect(ref.current).toBe(screen.getByText('Save').closest('.corn-badge'));
61
+ });
62
+
63
+ test('supports a callback ref', () => {
64
+ const ref = jest.fn();
65
+ render(<CornBadge ref={ref}>Save</CornBadge>);
66
+
67
+ expect(ref).toHaveBeenCalledWith(screen.getByText('Save').closest('.corn-badge'));
68
+ });
69
+ });
@@ -0,0 +1,10 @@
1
+ import { joinClassNames } from '../../utils/class-names.js';
2
+ import '../../custom-elements.js';
3
+
4
+ export function CornButtonBar({ ref, className = '', overflowLabel, children, ...props }) {
5
+ return (
6
+ <corn-button-bar {...props} ref={ref} className={joinClassNames('corn-button-bar', className)} overflow-label={overflowLabel}>
7
+ {children}
8
+ </corn-button-bar>
9
+ );
10
+ }
@@ -0,0 +1,86 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom/client';
3
+ import { CornButton, CornButtonBar } from '../../index.js';
4
+
5
+ function BasicButtonBar() {
6
+ const labels = ['Button 1', 'Button 2', 'Button 3', 'Button 4', 'Button 5', 'Button 6', 'Button 7', 'Button 8'];
7
+
8
+ return (
9
+ <CornButtonBar>
10
+ {labels.map((label, index) => (
11
+ <CornButton key={label} size={index === 1 ? 'sm' : 'xs'} type="button">
12
+ {label}
13
+ </CornButton>
14
+ ))}
15
+ </CornButtonBar>
16
+ );
17
+ }
18
+
19
+ function ComplexButtonBar() {
20
+ return (
21
+ <CornButtonBar className="corn-button-bar--toolbar">
22
+ <CornButton size="xs" type="button">
23
+ Button 1
24
+ </CornButton>
25
+ <CornButton size="sm" type="button">
26
+ Button 2
27
+ </CornButton>
28
+ <CornButton size="xs" type="button">
29
+ Button 3
30
+ </CornButton>
31
+ <CornButton size="xs" type="button">
32
+ Button 4
33
+ </CornButton>
34
+ <CornButton size="xs" type="button">
35
+ Button 5
36
+ </CornButton>
37
+ <CornButton size="xs" type="button">
38
+ Button 6
39
+ </CornButton>
40
+
41
+ <div className="corn-popover--anchor">
42
+ <button className="corn-button corn-pop corn-button--xs" aria-controls="nest-popover-bottom" type="button">
43
+ Popover
44
+ </button>
45
+ <corn-popover position="bottom" id="nest-popover-bottom" className="corn-popover">
46
+ <ul>
47
+ <li>
48
+ <a href="#">Item 1</a>
49
+ </li>
50
+ <li>
51
+ <a href="#">Item 2</a>
52
+ </li>
53
+ <li>
54
+ <a href="#">Item 3</a>
55
+ </li>
56
+ </ul>
57
+ </corn-popover>
58
+ </div>
59
+
60
+ <CornButton size="xs" type="button">
61
+ Button 8
62
+ </CornButton>
63
+
64
+ <button className="corn-button corn-button--icon corn-button--xs" aria-label="More" slot="more-button" type="button">
65
+ <svg xmlns="http://www.w3.org/2000/svg" className="corn-icon" aria-hidden="true">
66
+ <use href="/node_modules/bootstrap-icons/bootstrap-icons.svg#three-dots" fill="currentColor"></use>
67
+ </svg>
68
+ </button>
69
+ </CornButtonBar>
70
+ );
71
+ }
72
+
73
+ const root = ReactDOM.createRoot(document.getElementById('test-stickersheet'));
74
+ root.render(
75
+ <div className="buttonbar-demo" style={{ maxWidth: '500px' }}>
76
+ <h2>Corn Button Bar</h2>
77
+
78
+ <h3>Basic Button Bar</h3>
79
+ <BasicButtonBar />
80
+
81
+ <hr />
82
+
83
+ <h3>Complex Button Bar</h3>
84
+ <ComplexButtonBar />
85
+ </div>
86
+ );
@@ -0,0 +1,58 @@
1
+ import { createRef } from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import { renderToString } from 'react-dom/server';
4
+ import { CornButtonBar } from './button-bar.jsx';
5
+
6
+ describe('CornButtonBar', () => {
7
+ test('renders corn-button-bar host with base class', () => {
8
+ const { container } = render(
9
+ <CornButtonBar>
10
+ <button className="corn-button" type="button">
11
+ One
12
+ </button>
13
+ </CornButtonBar>
14
+ );
15
+
16
+ const host = container.querySelector('corn-button-bar');
17
+ expect(host).toBeTruthy();
18
+ expect(host).toHaveClass('corn-button-bar');
19
+ });
20
+
21
+ test('passes overflow label attribute to web component', () => {
22
+ const { container } = render(
23
+ <CornButtonBar overflowLabel="More">
24
+ <button className="corn-button" type="button">
25
+ One
26
+ </button>
27
+ </CornButtonBar>
28
+ );
29
+
30
+ expect(container.querySelector('corn-button-bar')).toHaveAttribute('overflow-label', 'More');
31
+ });
32
+
33
+ test('forwards ref to corn-button-bar host', () => {
34
+ const ref = createRef();
35
+ render(
36
+ <CornButtonBar ref={ref}>
37
+ <button className="corn-button" type="button">
38
+ One
39
+ </button>
40
+ </CornButtonBar>
41
+ );
42
+
43
+ expect(ref.current.tagName).toBe('CORN-BUTTON-BAR');
44
+ });
45
+
46
+ test('forwards a callback ref', () => {
47
+ const ref = jest.fn();
48
+ const { container } = render(<CornButtonBar ref={ref} />);
49
+
50
+ expect(ref).toHaveBeenCalledWith(container.querySelector('corn-button-bar'));
51
+ });
52
+
53
+ test('renders the overflow label in server markup', () => {
54
+ const html = renderToString(<CornButtonBar overflowLabel="More" />);
55
+
56
+ expect(html).toContain('overflow-label="More"');
57
+ });
58
+ });
@@ -0,0 +1,15 @@
1
+ import { useFormStatus } from 'react-dom';
2
+ import { joinClassNames, modifierClass } from '../../utils/class-names.js';
3
+
4
+ export function CornButton({ ref, variant = 'primary', size = 'md', icon = false, type = 'button', as: Component = 'button', className = '', disabled, children, ...props }) {
5
+ const { pending } = useFormStatus();
6
+ const isNativeButton = Component === 'button';
7
+ const isPendingSubmit = isNativeButton && type === 'submit' && pending;
8
+ const classNames = joinClassNames('corn-button', modifierClass('corn-button--', variant, ['primary']), modifierClass('corn-button--', size, ['md']), icon && 'corn-button--icon', className);
9
+
10
+ return (
11
+ <Component {...props} ref={ref} type={isNativeButton ? type : undefined} disabled={isNativeButton && type === 'submit' ? (disabled ?? isPendingSubmit) : disabled} aria-busy={isPendingSubmit || undefined} className={classNames}>
12
+ {children}
13
+ </Component>
14
+ );
15
+ }