paris 0.7.0 → 0.8.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # paris
2
2
 
3
+ ## 0.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - c3a5648: Allow for title in paginated drawer
8
+ - 963e618: Pagination: add `reset` function to reset the history state
9
+
10
+ ## 0.8.0
11
+
12
+ ### Minor Changes
13
+
14
+ - 9192ce2: Button: rename `hrefTarget` prop to `hreftarget` for React compatibility
15
+
16
+ ### Patch Changes
17
+
18
+ - 30bb138: Accordion: allow uncontrolled state management
19
+
3
20
  ## 0.7.0
4
21
 
5
22
  ### Minor Changes
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "paris",
3
3
  "author": "Sanil Chawla <sanil@slingshot.fm> (https://sanil.co)",
4
4
  "description": "Paris is Slingshot's React design system. It's a collection of reusable components, design tokens, and guidelines that help us build consistent, accessible, and performant user interfaces.",
5
- "version": "0.7.0",
5
+ "version": "0.8.1",
6
6
  "homepage": "https://paris.slingshot.fm",
7
7
  "license": "MIT",
8
8
  "repository": {
@@ -10,6 +10,10 @@ import { TextWhenString } from '../utility';
10
10
  export type AccordionProps = {
11
11
  /** The title of the Accordion. */
12
12
  title?: ReactNode;
13
+ /** Whether the Accordion is open. If provided, the Accordion will be a controlled component. */
14
+ isOpen?: boolean;
15
+ /** A handler for when the Accordion state changes. */
16
+ onOpenChange?: (open: boolean) => void | Promise<void>;
13
17
  /** The collapsible contents of the Accordion. */
14
18
  children?: ReactNode;
15
19
  };
@@ -28,9 +32,11 @@ export type AccordionProps = {
28
32
  */
29
33
  export const Accordion: FC<AccordionProps> = ({
30
34
  title,
35
+ isOpen,
36
+ onOpenChange,
31
37
  children,
32
38
  }) => {
33
- const [open, setOpen] = useState(false);
39
+ const [open, setOpen] = useState(isOpen ?? false);
34
40
 
35
41
  return (
36
42
  <div
@@ -43,6 +49,7 @@ export const Accordion: FC<AccordionProps> = ({
43
49
  if (e.key === 'Enter' || e.key === ' ') {
44
50
  e.preventDefault();
45
51
  setOpen((o) => !o);
52
+ onOpenChange?.(!open);
46
53
  }
47
54
  }}
48
55
  role="button"
@@ -98,7 +98,7 @@ export type ButtonProps = {
98
98
  /**
99
99
  * Optionally, the target of the anchor element can be specified (defaults to `_self`).
100
100
  */
101
- hrefTarget?: HTMLAttributeAnchorTarget;
101
+ hreftarget?: HTMLAttributeAnchorTarget;
102
102
  /**
103
103
  * The contents of the Button.
104
104
  *
@@ -163,8 +163,8 @@ export const Button: FC<ButtonProps> = ({
163
163
  <a
164
164
  {...properties}
165
165
  href={href}
166
- target={props.hrefTarget ?? '_self'}
167
- rel={props.hrefTarget === '_self' ? undefined : 'noreferrer'}
166
+ target={props.hreftarget ?? '_self'}
167
+ rel={props.hreftarget === '_self' ? undefined : 'noreferrer'}
168
168
  />
169
169
  ),
170
170
  } : {}}
@@ -292,11 +292,11 @@ $panelAnimationDelay: var(--pte-animations-duration-fast);
292
292
  }
293
293
  }
294
294
 
295
- .paginationButtons {
295
+ .paginationTitle {
296
296
  display: flex;
297
297
  flex-direction: row;
298
298
  align-items: center;
299
- gap: 8px;
299
+ gap: 12px;
300
300
  }
301
301
 
302
302
  .enter {
@@ -42,7 +42,6 @@ export const Default: Story = {
42
42
 
43
43
  export const Paginated: Story = {
44
44
  args: {
45
- title: 'Creation process',
46
45
  children: [],
47
46
  },
48
47
  render: (args) => {
@@ -50,6 +49,12 @@ export const Paginated: Story = {
50
49
  const pages = ['step1', 'step2', 'step3'] as const;
51
50
  const pagination = usePagination<typeof pages>('step1');
52
51
 
52
+ const currentPageTitle = {
53
+ step1: 'Step 1',
54
+ step2: 'Step 2',
55
+ step3: 'Step 3',
56
+ }[pagination.currentPage];
57
+
53
58
  return (
54
59
  <>
55
60
  <Button
@@ -62,6 +67,7 @@ export const Paginated: Story = {
62
67
  isOpen={isOpen}
63
68
  onClose={setIsOpen}
64
69
  pagination={pagination}
70
+ title={currentPageTitle}
65
71
  >
66
72
  <div key="step1" style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
67
73
  Step 1: Enter your name
@@ -273,7 +273,7 @@ export const Drawer = <T extends string[] | readonly string[] = string[]>({
273
273
  >
274
274
  <div
275
275
  className={clsx(
276
- styles.paginationButtons,
276
+ styles.paginationTitle,
277
277
  )}
278
278
  >
279
279
  <Button
@@ -306,6 +306,16 @@ export const Drawer = <T extends string[] | readonly string[] = string[]>({
306
306
  >
307
307
  Go to next page in this modal
308
308
  </Button>
309
+ <VisuallyHidden
310
+ // Hide when requested, or when pagination is enabled (the title isn't relevant to any specific page).
311
+ when={hideTitle}
312
+ >
313
+ <Dialog.Title as="h2" className={styles.titleTextContainer}>
314
+ <TextWhenString kind="paragraphSmall" weight="medium">
315
+ {title}
316
+ </TextWhenString>
317
+ </Dialog.Title>
318
+ </VisuallyHidden>
309
319
  </div>
310
320
  <Button
311
321
  kind="tertiary"
@@ -40,6 +40,11 @@ export type PaginationState<T extends string[] | readonly string[] = string[]> =
40
40
  * The page history.
41
41
  */
42
42
  history: T[number][],
43
+
44
+ /**
45
+ * Clear the page history and reset to the initial page.
46
+ */
47
+ reset: () => void,
43
48
  };
44
49
 
45
50
  /**
@@ -94,6 +99,11 @@ export const usePagination = <T extends string[] | readonly string[] = string[]>
94
99
  }
95
100
  };
96
101
 
102
+ const reset = (): void => {
103
+ setCurrentPage(initialPage);
104
+ setHistory([initialPage]);
105
+ };
106
+
97
107
  return {
98
108
  currentPage,
99
109
  open,
@@ -101,6 +111,7 @@ export const usePagination = <T extends string[] | readonly string[] = string[]>
101
111
  back,
102
112
  canGoForward,
103
113
  forward,
114
+ reset,
104
115
  history,
105
116
  } as PaginationState<T>;
106
117
  };