paris 0.8.0 → 0.8.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # paris
2
2
 
3
+ ## 0.8.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 5206e66: Input, Select: `forwardRef`
8
+
9
+ ## 0.8.1
10
+
11
+ ### Patch Changes
12
+
13
+ - c3a5648: Allow for title in paginated drawer
14
+ - 963e618: Pagination: add `reset` function to reset the history state
15
+
3
16
  ## 0.8.0
4
17
 
5
18
  ### 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.8.0",
5
+ "version": "0.8.2",
6
6
  "homepage": "https://paris.slingshot.fm",
7
7
  "license": "MIT",
8
8
  "repository": {
@@ -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"
@@ -1,13 +1,12 @@
1
1
  'use client';
2
2
 
3
- import { useId } from 'react';
4
- import type { FC, ComponentPropsWithoutRef } from 'react';
3
+ import { forwardRef, useId } from 'react';
4
+ import type { FC, ComponentPropsWithoutRef, ForwardedRef } from 'react';
5
5
  import clsx from 'clsx';
6
6
  import styles from './Input.module.scss';
7
7
  import type { TextProps } from '../text';
8
- import { Text } from '../text';
9
8
  import type { Enhancer } from '../../types/Enhancer';
10
- import { pget, theme } from '../theme';
9
+ import { theme } from '../theme';
11
10
  import { MemoizedEnhancer } from '../../helpers/renderEnhancer';
12
11
  import type { FieldProps } from '../field';
13
12
  import { Field } from '../field';
@@ -65,7 +64,7 @@ export type InputProps = {
65
64
  * ```
66
65
  * @constructor
67
66
  */
68
- export const Input: FC<InputProps & ComponentPropsWithoutRef<'input'>> = ({
67
+ export const Input: FC<InputProps & ComponentPropsWithoutRef<'input'>> = forwardRef(({
69
68
  label,
70
69
  status,
71
70
  type,
@@ -77,7 +76,7 @@ export const Input: FC<InputProps & ComponentPropsWithoutRef<'input'>> = ({
77
76
  disabled,
78
77
  overrides,
79
78
  ...props
80
- }) => {
79
+ }, ref: ForwardedRef<HTMLInputElement>) => {
81
80
  const inputID = useId();
82
81
  return (
83
82
  <Field
@@ -117,6 +116,7 @@ export const Input: FC<InputProps & ComponentPropsWithoutRef<'input'>> = ({
117
116
  <input
118
117
  {...props}
119
118
  id={inputID}
119
+ ref={ref}
120
120
  type={type || 'text'}
121
121
  aria-label={typeof label === 'string' ? label : props['aria-label']}
122
122
  aria-describedby={`${inputID}-description`}
@@ -140,4 +140,4 @@ export const Input: FC<InputProps & ComponentPropsWithoutRef<'input'>> = ({
140
140
  </div>
141
141
  </Field>
142
142
  );
143
- };
143
+ });
@@ -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
  };
@@ -1,11 +1,13 @@
1
+ /* eslint-disable prefer-arrow-callback,func-names */
2
+
1
3
  'use client';
2
4
 
3
- import type { ReactNode, ComponentPropsWithoutRef } from 'react';
5
+ import type { ReactNode, ComponentPropsWithoutRef, ForwardedRef } from 'react';
4
6
  import { Listbox, RadioGroup, Transition } from '@headlessui/react';
5
7
  import clsx from 'clsx';
6
8
  import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
7
9
  import { faChevronDown } from '@fortawesome/free-solid-svg-icons';
8
- import { useId } from 'react';
10
+ import { forwardRef, useId } from 'react';
9
11
  import inputStyles from '../input/Input.module.scss';
10
12
  import dropdownStyles from '../utility/Dropdown.module.scss';
11
13
  import styles from './Select.module.scss';
@@ -75,7 +77,7 @@ export type SelectProps<T = Record<string, any>> = {
75
77
  * ```
76
78
  * @constructor
77
79
  */
78
- export function Select<T = Record<string, any>>({
80
+ export const Select = forwardRef(function <T = Record<string, any>>({
79
81
  options,
80
82
  value,
81
83
  onChange,
@@ -90,7 +92,7 @@ export function Select<T = Record<string, any>>({
90
92
  disabled,
91
93
  kind = 'listbox',
92
94
  overrides,
93
- }: SelectProps<T>) {
95
+ }: SelectProps<T>, ref: ForwardedRef<any>) {
94
96
  const inputID = useId();
95
97
  return (
96
98
  <Field
@@ -109,6 +111,7 @@ export function Select<T = Record<string, any>>({
109
111
  {kind === 'listbox' && (
110
112
  <Listbox
111
113
  as="div"
114
+ ref={ref}
112
115
  value={value}
113
116
  onChange={onChange}
114
117
  >
@@ -184,7 +187,7 @@ export function Select<T = Record<string, any>>({
184
187
  </Listbox>
185
188
  )}
186
189
  {kind === 'radio' && (
187
- <RadioGroup as="div" className={styles.radioContainer} value={value} onChange={onChange}>
190
+ <RadioGroup ref={ref} as="div" className={styles.radioContainer} value={value} onChange={onChange}>
188
191
  {options.map((option) => (
189
192
  <RadioGroup.Option
190
193
  as="div"
@@ -205,4 +208,4 @@ export function Select<T = Record<string, any>>({
205
208
  )}
206
209
  </Field>
207
210
  );
208
- }
211
+ });