@arbor-education/design-system.components 0.24.2 → 0.25.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.
@@ -66,11 +66,11 @@ const DEVELOPER_NOTES = [
66
66
  '',
67
67
  '---',
68
68
  '',
69
- '### Button props must all be provided together',
69
+ '### Pass all button props via `headerButtonProps`',
70
70
  '',
71
- 'The action button only renders when `buttonText` is provided.',
72
- 'When adding a button, always supply all four props together: `buttonText`, `buttonOnClick`, `buttonVariant`, and `buttonSize`.',
73
- 'If any are omitted, the `Button` component falls back to its own defaults, which may produce unexpected visual results.',
71
+ 'The action button only renders when `headerButtonProps` is provided.',
72
+ 'Pass a single `headerButtonProps` object containing at minimum `children` (button label) and `onClick`.',
73
+ 'Always include `variant` and `size` to avoid relying on `Button` defaults, which may not look right in the heading context.',
74
74
  '',
75
75
  '---',
76
76
  '',
@@ -213,41 +213,16 @@ const meta: Meta<typeof Section> = {
213
213
  defaultValue: { summary: 'false' },
214
214
  },
215
215
  },
216
- buttonText: {
216
+ headerButtonProps: {
217
217
  description: [
218
- 'Label for the action button rendered in the section heading.',
219
- 'Must be paired with `buttonOnClick`, `buttonVariant`, and `buttonSize`.',
218
+ 'Props forwarded directly to the `Button` component rendered in the section heading.',
219
+ 'Omit this prop entirely to render no button.',
220
+ 'When provided, always include `children` (button label), `onClick`, `variant`, and `size`',
221
+ "to avoid unexpected visual results from `Button` defaults. Use `size: 'S'` to keep it lightweight alongside the title.",
220
222
  ].join(' '),
221
- control: 'text',
222
- table: {
223
- type: { summary: 'string' },
224
- defaultValue: { summary: 'undefined' },
225
- },
226
- },
227
- buttonOnClick: {
228
- description: 'Click handler for the heading action button.',
229
- action: 'buttonOnClick',
230
223
  control: false,
231
224
  table: {
232
- type: { summary: 'MouseEventHandler<HTMLButtonElement>' },
233
- defaultValue: { summary: 'undefined' },
234
- },
235
- },
236
- buttonVariant: {
237
- description: 'Visual variant for the heading action button. Always supply when `buttonText` is set.',
238
- control: 'select',
239
- options: ['primary', 'secondary', 'tertiary', 'primary-destructive', 'secondary-destructive', 'tertiary-destructive', 'ghost'],
240
- table: {
241
- type: { summary: "'primary' | 'secondary' | 'tertiary' | 'primary-destructive' | 'secondary-destructive' | 'tertiary-destructive' | 'ghost'" },
242
- defaultValue: { summary: 'undefined' },
243
- },
244
- },
245
- buttonSize: {
246
- description: "Size of the heading action button. Always supply when `buttonText` is set. Use `'S'` to keep it visually lightweight alongside the title.",
247
- control: 'select',
248
- options: ['S', 'M', 'L'],
249
- table: {
250
- type: { summary: "'S' | 'M' | 'L'" },
225
+ type: { summary: 'ButtonProps' },
251
226
  defaultValue: { summary: 'undefined' },
252
227
  },
253
228
  },
@@ -311,7 +286,7 @@ export const Default: Story = withDescription(
311
286
  },
312
287
  render: args => <Section {...args} />,
313
288
  },
314
- 'The default story is wired to the Controls panel. Toggle `collapsible` to add expand/collapse behaviour, or add `buttonText` (with the three companion props) to surface an action in the heading.',
289
+ 'The default story is wired to the Controls panel. Toggle `collapsible` to add expand/collapse behaviour, or pass `headerButtonProps` to surface an action in the heading.',
315
290
  );
316
291
 
317
292
  export const WithHeadingLevel: Story = withDescription(
@@ -441,10 +416,13 @@ function PersonalDetailsSection() {
441
416
  <Section
442
417
  title="Personal Details"
443
418
  headingLevel={2}
444
- buttonText="Edit"
445
- buttonOnClick={() => openEditModal()}
446
- buttonVariant="secondary"
447
- buttonSize="S"
419
+ headerButtonProps={{
420
+ children: 'Edit',
421
+ iconLeftName: 'pencil',
422
+ onClick: () => openEditModal(),
423
+ variant: 'secondary',
424
+ size: 'S',
425
+ }}
448
426
  >
449
427
  <p>Section content here.</p>
450
428
  </Section>
@@ -459,26 +437,168 @@ export default PersonalDetailsSection;
459
437
  <Section
460
438
  title="Personal Details"
461
439
  headingLevel={2}
462
- buttonText="Edit"
463
- buttonOnClick={fn()}
464
- buttonVariant="secondary"
465
- buttonSize="S"
440
+ headerButtonProps={{
441
+ children: 'Edit',
442
+ iconLeftName: 'pencil',
443
+ onClick: fn(),
444
+ variant: 'secondary',
445
+ size: 'S',
446
+ }}
466
447
  >
467
448
  <p>
468
- The action button appears in the heading row. Always provide all four button props together:
469
- <code>buttonText</code>
470
- ,
471
- <code>buttonOnClick</code>
472
- ,
473
- <code>buttonVariant</code>
474
- , and
475
- <code>buttonSize</code>
476
- .
449
+ The action button appears in the heading row. Use
450
+ <code>iconLeftName</code>
451
+ {' '}
452
+ or
453
+ <code>iconRightName</code>
454
+ {' '}
455
+ inside
456
+ <code>headerButtonProps</code>
457
+ {' '}
458
+ to add an icon alongside the label.
477
459
  </p>
478
460
  </Section>
479
461
  ),
480
462
  },
481
- 'Provide all four button props together to render an action button in the section heading. Use `buttonSize="S"` to keep it visually lightweight alongside the title.',
463
+ 'Pass `headerButtonProps` to render an action button in the section heading. Icons can be added via `iconLeftName` or `iconRightName`. Use `size: "S"` to keep it visually lightweight alongside the title.',
464
+ );
465
+
466
+ export const WithActionButtonVariants: Story = withDescription(
467
+ {
468
+ parameters: {
469
+ controls: { disable: true },
470
+ docs: {
471
+ source: {
472
+ language: 'tsx',
473
+ code: `
474
+ import { Section } from '@arbor-education/design-system.components';
475
+
476
+ // Icon on the left
477
+ <Section title="Documents" headingLevel={2}
478
+ headerButtonProps={{ children: 'Upload', iconLeftName: 'upload', onClick: () => {}, variant: 'secondary', size: 'S' }}>
479
+ <p>...</p>
480
+ </Section>
481
+
482
+ // Icon on the right
483
+ <Section title="External Link" headingLevel={2}
484
+ headerButtonProps={{ children: 'Open', iconRightName: 'external-link', onClick: () => {}, variant: 'tertiary', size: 'S' }}>
485
+ <p>...</p>
486
+ </Section>
487
+
488
+ // Icon-only (no children — button renders in icon-only mode)
489
+ <Section title="Attachments" headingLevel={2}
490
+ headerButtonProps={{ iconLeftName: 'plus', iconLeftScreenReaderText: 'Add attachment', onClick: () => {}, variant: 'secondary', size: 'S' }}>
491
+ <p>...</p>
492
+ </Section>
493
+
494
+ // Destructive
495
+ <Section title="Danger Zone" headingLevel={2}
496
+ headerButtonProps={{ children: 'Delete', iconLeftName: 'trash', onClick: () => {}, variant: 'primary-destructive', size: 'S' }}>
497
+ <p>...</p>
498
+ </Section>
499
+
500
+ // Disabled
501
+ <Section title="Locked Section" headingLevel={2}
502
+ headerButtonProps={{ children: 'Edit', iconLeftName: 'pencil', onClick: () => {}, variant: 'secondary', size: 'S', disabled: true }}>
503
+ <p>...</p>
504
+ </Section>
505
+ `.trim(),
506
+ },
507
+ },
508
+ },
509
+ render: () => (
510
+ <>
511
+ <Section
512
+ title="Documents"
513
+ headingLevel={2}
514
+ headerButtonProps={{
515
+ children: 'Upload',
516
+ iconLeftName: 'upload',
517
+ onClick: fn(),
518
+ variant: 'secondary',
519
+ size: 'S',
520
+ }}
521
+ >
522
+ <p>Left icon — icon precedes the label.</p>
523
+ </Section>
524
+ <Section
525
+ title="External Link"
526
+ headingLevel={2}
527
+ headerButtonProps={{
528
+ children: 'Open',
529
+ iconRightName: 'external-link',
530
+ onClick: fn(),
531
+ variant: 'tertiary',
532
+ size: 'S',
533
+ }}
534
+ >
535
+ <p>Right icon — icon follows the label.</p>
536
+ </Section>
537
+ <Section
538
+ title="Attachments"
539
+ headingLevel={2}
540
+ headerButtonProps={{
541
+ iconLeftName: 'plus',
542
+ iconLeftScreenReaderText: 'Add attachment',
543
+ onClick: fn(),
544
+ variant: 'secondary',
545
+ size: 'S',
546
+ }}
547
+ >
548
+ <p>
549
+ Icon-only — omit
550
+ <code>children</code>
551
+ {' '}
552
+ and the button renders in compact icon-only mode. Always supply
553
+ <code>iconLeftScreenReaderText</code>
554
+ {' '}
555
+ for accessibility.
556
+ </p>
557
+ </Section>
558
+ <Section
559
+ title="Danger Zone"
560
+ headingLevel={2}
561
+ headerButtonProps={{
562
+ children: 'Delete',
563
+ iconLeftName: 'trash',
564
+ onClick: fn(),
565
+ variant: 'primary-destructive',
566
+ size: 'S',
567
+ }}
568
+ >
569
+ <p>
570
+ Destructive variant — use
571
+ <code>primary-destructive</code>
572
+ {' '}
573
+ or
574
+ <code>secondary-destructive</code>
575
+ {' '}
576
+ for irreversible actions.
577
+ </p>
578
+ </Section>
579
+ <Section
580
+ title="Locked Section"
581
+ headingLevel={2}
582
+ headerButtonProps={{
583
+ children: 'Edit',
584
+ iconLeftName: 'pencil',
585
+ onClick: fn(),
586
+ variant: 'secondary',
587
+ size: 'S',
588
+ disabled: true,
589
+ }}
590
+ >
591
+ <p>
592
+ Disabled — pass
593
+ <code>disabled: true</code>
594
+ {' '}
595
+ to prevent interaction while keeping the button visible.
596
+ </p>
597
+ </Section>
598
+ </>
599
+ ),
600
+ },
601
+ 'All `ButtonProps` are forwarded through `headerButtonProps`. This story covers the main edge cases: left icon, right icon, icon-only, destructive variant, and disabled state.',
482
602
  );
483
603
 
484
604
  export const Collapsible: Story = withDescription(
@@ -586,10 +706,12 @@ function ContactSection() {
586
706
  title="Contact Information"
587
707
  headingLevel={2}
588
708
  collapsible
589
- buttonText="Add contact"
590
- buttonOnClick={() => openAddContactModal()}
591
- buttonVariant="secondary"
592
- buttonSize="S"
709
+ headerButtonProps={{
710
+ children: 'Add contact',
711
+ onClick: () => openAddContactModal(),
712
+ variant: 'secondary',
713
+ size: 'S',
714
+ }}
593
715
  >
594
716
  <p>Contact details here.</p>
595
717
  </Section>
@@ -605,10 +727,12 @@ export default ContactSection;
605
727
  title="Contact Information"
606
728
  headingLevel={2}
607
729
  collapsible
608
- buttonText="Add contact"
609
- buttonOnClick={fn()}
610
- buttonVariant="secondary"
611
- buttonSize="S"
730
+ headerButtonProps={{
731
+ children: 'Add contact',
732
+ onClick: fn(),
733
+ variant: 'secondary',
734
+ size: 'S',
735
+ }}
612
736
  >
613
737
  <p>
614
738
  A section can be both collapsible
@@ -637,10 +761,12 @@ function PupilDetailSection() {
637
761
  <Section
638
762
  title="Personal Details"
639
763
  headingLevel={2}
640
- buttonText="Edit"
641
- buttonOnClick={() => openEditModal()}
642
- buttonVariant="secondary"
643
- buttonSize="S"
764
+ headerButtonProps={{
765
+ children: 'Edit',
766
+ onClick: () => openEditModal(),
767
+ variant: 'secondary',
768
+ size: 'S',
769
+ }}
644
770
  >
645
771
  <Row label="Full name" value="Amara Osei-Bonsu" />
646
772
  <Row label="Date of birth" value="14 March 2009" note="Age 16" />
@@ -659,10 +785,12 @@ export default PupilDetailSection;
659
785
  <Section
660
786
  title="Personal Details"
661
787
  headingLevel={2}
662
- buttonText="Edit"
663
- buttonOnClick={fn()}
664
- buttonVariant="secondary"
665
- buttonSize="S"
788
+ headerButtonProps={{
789
+ children: 'Edit',
790
+ onClick: fn(),
791
+ variant: 'secondary',
792
+ size: 'S',
793
+ }}
666
794
  >
667
795
  <Row label="Full name" value="Amara Osei-Bonsu" />
668
796
  <Row label="Date of birth" value="14 March 2009" note="Age 16" />
@@ -43,10 +43,12 @@ describe('Section component', () => {
43
43
  render(
44
44
  <Section
45
45
  title="Test Section"
46
- buttonText="Click Me"
47
- buttonOnClick={mockButtonClick}
48
- buttonVariant="primary"
49
- buttonSize="M"
46
+ headerButtonProps={{
47
+ children: 'Click Me',
48
+ onClick: mockButtonClick,
49
+ variant: 'primary',
50
+ size: 'M',
51
+ }}
50
52
  >
51
53
  <p>Section content</p>
52
54
  </Section>,
@@ -239,15 +241,19 @@ describe('Section component', () => {
239
241
  <Section
240
242
  title="Parent Section"
241
243
  collapsible
242
- buttonText="Parent Action"
243
- buttonOnClick={parentButtonClick}
244
+ headerButtonProps={{
245
+ children: 'Parent Action',
246
+ onClick: parentButtonClick,
247
+ }}
244
248
  titleIconName="info"
245
249
  >
246
250
  <p>Parent content</p>
247
251
  <Section
248
252
  title="Child Section"
249
- buttonText="Child Action"
250
- buttonOnClick={childButtonClick}
253
+ headerButtonProps={{
254
+ children: 'Child Action',
255
+ onClick: childButtonClick,
256
+ }}
251
257
  titleIconName="file"
252
258
  >
253
259
  <p>Child content</p>
@@ -1,9 +1,9 @@
1
1
  import classNames from 'classnames';
2
- import { Button, type ButtonSize, type ButtonVariant } from 'Components/button/Button';
2
+ import { Button, type ButtonProps } from 'Components/button/Button';
3
3
  import { Heading, type HeadingLevel } from 'Components/heading/Heading';
4
4
  import type { IconName } from 'Components/icon/allowedIcons';
5
5
  import { Icon } from 'Components/icon/Icon';
6
- import { useState, type HTMLAttributes, type MouseEventHandler } from 'react';
6
+ import { useState, type HTMLAttributes } from 'react';
7
7
  import { ENTER_KEY, SPACE_KEY } from 'Utils/keyboardConstants';
8
8
 
9
9
  type SectionProps = {
@@ -14,10 +14,7 @@ type SectionProps = {
14
14
  titleIconScreenReaderText?: string;
15
15
  collapsible?: boolean;
16
16
  collapsed?: boolean;
17
- buttonText?: string;
18
- buttonOnClick?: MouseEventHandler<HTMLButtonElement>;
19
- buttonVariant?: ButtonVariant;
20
- buttonSize?: ButtonSize;
17
+ headerButtonProps?: ButtonProps;
21
18
  } & HTMLAttributes<HTMLElement>;
22
19
 
23
20
  export const Section = (props: SectionProps) => {
@@ -31,10 +28,7 @@ export const Section = (props: SectionProps) => {
31
28
  titleIconScreenReaderText,
32
29
  collapsible = false,
33
30
  collapsed: initialCollapsed = false,
34
- buttonText,
35
- buttonOnClick,
36
- buttonVariant,
37
- buttonSize,
31
+ headerButtonProps,
38
32
  } = props;
39
33
 
40
34
  const [collapsed, setCollapsed] = useState(initialCollapsed);
@@ -90,13 +84,11 @@ export const Section = (props: SectionProps) => {
90
84
  )}
91
85
  </Heading.InnerContainer>
92
86
  <Heading.InnerContainer>
93
- {buttonText && (
87
+ {headerButtonProps && (
94
88
  <Button
95
- onClick={buttonOnClick}
96
- variant={buttonVariant}
97
- size={buttonSize}
89
+ {...headerButtonProps}
98
90
  >
99
- {buttonText}
91
+ {headerButtonProps.children}
100
92
  </Button>
101
93
  )}
102
94
  {collapsible && (
@@ -2038,7 +2038,7 @@ describe('Table', () => {
2038
2038
  // second tab should focus the button bypassing the cell
2039
2039
  await userEvent.tab();
2040
2040
  expect(focusFirstFocusableElementSpy).toHaveBeenCalledTimes(1);
2041
- const button = screen.getByText('Im a lovely button');
2041
+ const button = screen.getByRole('button', { name: 'Im a lovely button' });
2042
2042
  expect(button).toHaveFocus();
2043
2043
  });
2044
2044
  });
@@ -15,6 +15,23 @@
15
15
  }
16
16
 
17
17
  &__select-dropdown {
18
+ max-width: 100%;
19
+ min-width: 0;
20
+
21
+ .ds-button--dropdown {
22
+ max-width: 100%;
23
+ min-width: 0;
24
+ flex-shrink: 1;
25
+
26
+ .ds-button__content {
27
+ overflow: hidden;
28
+ text-overflow: ellipsis;
29
+ white-space: nowrap;
30
+ min-width: 0;
31
+ flex: 1;
32
+ }
33
+ }
34
+
18
35
  &--fill-cell {
19
36
  display: flex;
20
37
  width: 100%;