@bootsmonday/corncob-design-language-react 0.1.0 → 0.2.2

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 (133) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist-types/common/choice-name.d.ts +8 -0
  3. package/dist-types/common/field.d.ts +22 -0
  4. package/dist-types/common/form-item.d.ts +11 -0
  5. package/dist-types/components/badges/badge.d.ts +12 -0
  6. package/dist-types/components/button-bars/button-bar.d.ts +12 -0
  7. package/dist-types/components/buttons/button.d.ts +16 -0
  8. package/dist-types/components/checkboxes/checkbox-group.d.ts +13 -0
  9. package/dist-types/components/checkboxes/checkbox.d.ts +20 -0
  10. package/dist-types/components/expandables/expandable.d.ts +43 -0
  11. package/dist-types/components/footers/footer.d.ts +62 -0
  12. package/dist-types/components/headers/header.d.ts +72 -0
  13. package/dist-types/components/links/link.d.ts +22 -0
  14. package/dist-types/components/messages/message.d.ts +42 -0
  15. package/dist-types/components/modals/modal.d.ts +30 -0
  16. package/dist-types/components/panel-menus/panel-menu.d.ts +33 -0
  17. package/dist-types/components/panels/panel.d.ts +11 -0
  18. package/dist-types/components/popovers/popover.d.ts +35 -0
  19. package/dist-types/components/radio-buttons/radio-button-group.d.ts +13 -0
  20. package/dist-types/components/radio-buttons/radio-button.d.ts +18 -0
  21. package/dist-types/components/selects/select.d.ts +14 -0
  22. package/dist-types/components/sliders/slider.d.ts +7 -0
  23. package/dist-types/components/text-inputs/text-input.d.ts +6 -0
  24. package/dist-types/components/toasts/toast.d.ts +7 -0
  25. package/dist-types/components/toggles/toggle.d.ts +13 -0
  26. package/dist-types/components/tooltips/tooltip.d.ts +8 -0
  27. package/dist-types/custom-elements.d.ts +3 -0
  28. package/dist-types/index.d.ts +24 -0
  29. package/dist-types/utils/assign-ref.d.ts +7 -0
  30. package/dist-types/utils/class-names.d.ts +14 -0
  31. package/package.json +29 -8
  32. package/src/common/choice-name.js +7 -0
  33. package/src/common/field.jsx +17 -0
  34. package/src/common/form-item.jsx +5 -0
  35. package/src/components/badges/badge.jsx +5 -0
  36. package/src/components/button-bars/button-bar.jsx +5 -1
  37. package/src/components/buttons/button.jsx +5 -1
  38. package/src/components/checkboxes/checkbox-group.jsx +5 -0
  39. package/src/components/checkboxes/checkbox.jsx +5 -0
  40. package/src/components/expandables/expandable.jsx +20 -0
  41. package/src/components/footers/footer.jsx +30 -0
  42. package/src/components/headers/header.jsx +35 -0
  43. package/src/components/links/link.jsx +10 -0
  44. package/src/components/messages/message.jsx +20 -0
  45. package/src/components/modals/modal.jsx +15 -0
  46. package/src/components/panel-menus/panel-menu.jsx +15 -0
  47. package/src/components/panels/panel.jsx +5 -0
  48. package/src/components/popovers/popover.jsx +15 -0
  49. package/src/components/radio-buttons/radio-button-group.jsx +5 -0
  50. package/src/components/radio-buttons/radio-button.jsx +5 -0
  51. package/src/components/selects/select.jsx +10 -0
  52. package/src/components/sliders/slider.jsx +5 -0
  53. package/src/components/text-inputs/text-input.jsx +5 -0
  54. package/src/components/toasts/toast.jsx +5 -0
  55. package/src/components/toggles/toggle.jsx +10 -0
  56. package/src/components/tooltips/tooltip.jsx +5 -0
  57. package/src/custom-elements.d.ts +9 -0
  58. package/src/utils/assign-ref.js +6 -0
  59. package/src/utils/class-names.js +12 -0
  60. package/.changelog/README.md +0 -33
  61. package/jest.config.cjs +0 -17
  62. package/jest.setup.cjs +0 -19
  63. package/src/common/choice-name.test.js +0 -46
  64. package/src/common/field.test.js +0 -33
  65. package/src/common/form-item.test.js +0 -45
  66. package/src/components/badges/badge.stickersheet.jsx +0 -39
  67. package/src/components/badges/badge.test.js +0 -69
  68. package/src/components/button-bars/button-bar.stickersheet.jsx +0 -86
  69. package/src/components/button-bars/button-bar.test.js +0 -58
  70. package/src/components/buttons/button.stickersheet.jsx +0 -204
  71. package/src/components/buttons/button.test.js +0 -84
  72. package/src/components/checkboxes/checkbox.stickersheet.jsx +0 -53
  73. package/src/components/checkboxes/checkbox.test.js +0 -154
  74. package/src/components/expandables/expandable.stickersheet.jsx +0 -100
  75. package/src/components/expandables/expandable.test.js +0 -125
  76. package/src/components/footers/footer.stickersheet.jsx +0 -77
  77. package/src/components/footers/footer.test.js +0 -64
  78. package/src/components/headers/header.stickersheet.jsx +0 -63
  79. package/src/components/headers/header.test.js +0 -63
  80. package/src/components/links/link.stickersheet.jsx +0 -75
  81. package/src/components/links/link.test.js +0 -70
  82. package/src/components/messages/message.stickersheet.jsx +0 -96
  83. package/src/components/messages/message.test.js +0 -92
  84. package/src/components/modals/modal.stickersheet.jsx +0 -44
  85. package/src/components/modals/modal.test.js +0 -32
  86. package/src/components/panel-menus/panel-menu.stickersheet.jsx +0 -34
  87. package/src/components/panel-menus/panel-menu.test.js +0 -98
  88. package/src/components/panels/panel.stickersheet.jsx +0 -13
  89. package/src/components/panels/panel.test.js +0 -54
  90. package/src/components/popovers/popover.stickersheet.jsx +0 -236
  91. package/src/components/popovers/popover.test.js +0 -98
  92. package/src/components/radio-buttons/radio-button.stickersheet.jsx +0 -40
  93. package/src/components/radio-buttons/radio-button.test.js +0 -119
  94. package/src/components/selects/select.stickersheet.jsx +0 -34
  95. package/src/components/selects/select.test.js +0 -119
  96. package/src/components/sliders/slider.stickersheet.jsx +0 -29
  97. package/src/components/sliders/slider.test.js +0 -81
  98. package/src/components/text-inputs/text-input.stickersheet.jsx +0 -41
  99. package/src/components/text-inputs/text-input.test.js +0 -83
  100. package/src/components/toasts/toast.stickersheet.jsx +0 -54
  101. package/src/components/toasts/toast.test.js +0 -50
  102. package/src/components/toggles/toggle.stickersheet.jsx +0 -81
  103. package/src/components/toggles/toggle.test.js +0 -165
  104. package/src/components/tooltips/tooltip.stickersheet.jsx +0 -34
  105. package/src/components/tooltips/tooltip.test.js +0 -60
  106. package/src/stickersheets/badges.html +0 -31
  107. package/src/stickersheets/button-bars.html +0 -29
  108. package/src/stickersheets/buttons-standard.html +0 -33
  109. package/src/stickersheets/checkboxes.html +0 -32
  110. package/src/stickersheets/expandables.html +0 -29
  111. package/src/stickersheets/footers.html +0 -29
  112. package/src/stickersheets/headers.html +0 -29
  113. package/src/stickersheets/index.html +0 -56
  114. package/src/stickersheets/links.html +0 -29
  115. package/src/stickersheets/messages.html +0 -29
  116. package/src/stickersheets/modals.html +0 -29
  117. package/src/stickersheets/panel-menus.html +0 -29
  118. package/src/stickersheets/panels.html +0 -29
  119. package/src/stickersheets/popovers.html +0 -29
  120. package/src/stickersheets/radio-buttons.html +0 -32
  121. package/src/stickersheets/select.html +0 -31
  122. package/src/stickersheets/sliders.html +0 -31
  123. package/src/stickersheets/src/stickersheet-controls.html +0 -13
  124. package/src/stickersheets/src/stickersheet-header.html +0 -17
  125. package/src/stickersheets/src/stickersheet-react-header.html +0 -17
  126. package/src/stickersheets/src/stickersheet.css +0 -17
  127. package/src/stickersheets/src/stickersheet.js +0 -80
  128. package/src/stickersheets/text-inputs.html +0 -31
  129. package/src/stickersheets/toasts.html +0 -29
  130. package/src/stickersheets/toggles.html +0 -32
  131. package/src/stickersheets/tooltips.html +0 -29
  132. package/src/utils/assign-ref.test.js +0 -35
  133. package/src/utils/class-names.test.js +0 -21
@@ -5,6 +5,11 @@ import { joinClassNames, modifierClass } from '../../utils/class-names.js';
5
5
 
6
6
  const ASSISTIVE_SIZES = new Set(['xs', 'sm']);
7
7
 
8
+ /**
9
+ * Renders a text input component with the specified ref, size, label, id, status, status variant, placeholder, disabled state, class name, item class name, label class name, aria-invalid state, and children.
10
+ * @param {*} param0 The props for the CornTextInput component.
11
+ * @returns {JSX.Element} The rendered CornTextInput component.
12
+ */
8
13
  export function CornTextInput({ ref, size = 'md', label, id, status, statusVariant, placeholder, disabled, className = '', itemClassName = '', labelClassName, 'aria-invalid': ariaInvalid, children, ...inputProps }) {
9
14
  const generatedId = useId();
10
15
  const inputId = id ?? generatedId;
@@ -1,6 +1,11 @@
1
1
  import { joinClassNames } from '../../utils/class-names.js';
2
2
  import '../../custom-elements.js';
3
3
 
4
+ /**
5
+ * Renders a toast component with the specified ref, class name, children, and other props.
6
+ * @param {*} param0 The props for the CornToast component.
7
+ * @returns {JSX.Element} The rendered CornToast component.
8
+ */
4
9
  export function CornToast({ ref, className = '', children, ...props }) {
5
10
  return (
6
11
  <corn-toast {...props} ref={ref} className={joinClassNames('corn-toast', className)}>
@@ -5,6 +5,11 @@ import { joinClassNames, modifierClass } from '../../utils/class-names.js';
5
5
 
6
6
  export const CORN_TOGGLE_SIZES = ['xs', 'sm', 'md', 'lg', 'xl'];
7
7
 
8
+ /**
9
+ * Renders a toggle component with the specified ref, id, name, label, class name, checked state, default checked state, disabled state, change handler, value, and children.
10
+ * @param {*} param0 The props for the CornToggle component.
11
+ * @returns {JSX.Element} The rendered CornToggle component.
12
+ */
8
13
  export function CornToggle({ ref, id, name, label, className = '', checked, defaultChecked = false, disabled = false, onChange, value, children, ...inputProps }) {
9
14
  const generatedId = useId();
10
15
  const inputId = id ?? generatedId;
@@ -31,6 +36,11 @@ export function CornToggle({ ref, id, name, label, className = '', checked, defa
31
36
  );
32
37
  }
33
38
 
39
+ /**
40
+ * Renders a toggle group component with the specified ref, legend, name, size, class name, toggles class name, and children.
41
+ * @param {*} param0 The props for the CornToggleGroup component.
42
+ * @returns {JSX.Element} The rendered CornToggleGroup component.
43
+ */
34
44
  export function CornToggleGroup({ ref, legend, name, size = 'md', className = '', togglesClassName = '', children, ...props }) {
35
45
  return (
36
46
  <CornFormItem {...props} ref={ref} as="fieldset" className={joinClassNames('corn-toggle-group', modifierClass('corn-toggle--', size), className)}>
@@ -3,6 +3,11 @@ import '../../custom-elements.js';
3
3
 
4
4
  export const CORN_TOOLTIP_POSITIONS = ['top', 'right', 'bottom', 'left'];
5
5
 
6
+ /**
7
+ * Renders a tooltip component with the specified ref, position, class name, children, and other props.
8
+ * @param {*} param0 The props for the CornTooltip component.
9
+ * @returns {JSX.Element} The rendered CornTooltip component.
10
+ */
6
11
  export function CornTooltip({ ref, position = 'top', className = '', children, ...props }) {
7
12
  return (
8
13
  <corn-tooltip {...props} ref={ref} position={position} className={joinClassNames('corn-tooltip', className)}>
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Type boundary for the React package.
3
+ *
4
+ * Components import ./custom-elements.js so the vanilla elements register at
5
+ * runtime. This declaration is resolved instead of that implementation, which
6
+ * keeps tsc from following those imports and writing .d.ts files next to the
7
+ * standard JS components.
8
+ */
9
+ export {};
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Assigns a reference to a DOM node or component instance.
3
+ * @param {*} ref The reference to assign.
4
+ * @param {*} node The DOM node or component instance.
5
+ * @returns {Function|undefined} A cleanup function if applicable.
6
+ */
1
7
  export function assignRef(ref, node) {
2
8
  if (typeof ref === 'function') {
3
9
  const cleanup = ref(node);
@@ -1,7 +1,19 @@
1
+ /**
2
+ * Joins multiple class name parts into a single string, filtering out falsy values.
3
+ * @param {...string} parts The class name parts to join.
4
+ * @returns {string} The joined class name string.
5
+ */
1
6
  export function joinClassNames(...parts) {
2
7
  return parts.filter(Boolean).join(' ');
3
8
  }
4
9
 
10
+ /**
11
+ * Generates a modifier class name based on the given prefix and value, optionally omitting certain values.
12
+ * @param {string} prefix The prefix for the modifier class.
13
+ * @param {string|boolean|null|undefined} value The value to append to the prefix.
14
+ * @param {Array<string>} omit The list of values to omit.
15
+ * @returns {string} The generated modifier class name or an empty string if omitted.
16
+ */
5
17
  export function modifierClass(prefix, value, omit = []) {
6
18
  if (value == null || value === '' || value === false) return '';
7
19
  if (omit.includes(value)) return '';
@@ -1,33 +0,0 @@
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/jest.config.cjs DELETED
@@ -1,17 +0,0 @@
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 DELETED
@@ -1,19 +0,0 @@
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
- }
@@ -1,46 +0,0 @@
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
- });
@@ -1,33 +0,0 @@
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
- });
@@ -1,45 +0,0 @@
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
- });
@@ -1,39 +0,0 @@
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
- );
@@ -1,69 +0,0 @@
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
- });
@@ -1,86 +0,0 @@
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
- );
@@ -1,58 +0,0 @@
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
- });