rl-react-components 2.6.0 → 3.0.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.
package/README.md CHANGED
@@ -89,17 +89,17 @@ override any of them in its own CSS.
89
89
 
90
90
  ## What is inside
91
91
 
92
- | Group | Components and hooks |
93
- | -------------- | ------------------------------------------------------- |
94
- | Foundations | `Text`, `Icon` |
95
- | Layout | `Container`, `Section`, `PageHero`, `PageTransition` |
96
- | Navigation | `SideNav` |
97
- | Forms | `Button`, `TextInput`, `TextArea`, `Select`, `Checkbox` |
98
- | Tags | `Tag`, `TagFilter` |
99
- | Content | `Card`, `Markdown`, `MarkdownEditor`, `ShimmerImage` |
100
- | Feedback | `ToastProvider`, `useToast` |
101
- | Canvas effects | `MatrixContainer`, `OrbitalDots` |
102
- | Hooks | `useDragReorder`, `useRotatingMessage` |
92
+ | Group | Components and hooks |
93
+ | -------------- | ------------------------------------------------------------------------------------------------------------- |
94
+ | Foundations | `Text`, `Icon` |
95
+ | Layout | `Container`, `Section`, `PageHero`, `PageTransition` |
96
+ | Navigation | `SideNav`, `Tabs` |
97
+ | Forms | `Button`, `IconButton`, `TextInput`, `TextArea`, `Select`, `Checkbox`, `Switch`, `SegmentedControl`, `Slider` |
98
+ | Tags | `Tag`, `TagFilter`, `TagGroup`, `LevelChip` |
99
+ | Content | `Card`, `Accordion`, `Markdown`, `MarkdownEditor`, `ShimmerImage` |
100
+ | Feedback | `ToastProvider`, `useToast` |
101
+ | Canvas effects | `MatrixContainer`, `OrbitalDots` |
102
+ | Hooks | `useDragReorder`, `useRotatingMessage` |
103
103
 
104
104
  ## Documentation
105
105
 
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ export interface AccordionItem {
3
+ /** Tells the items apart, and names the ones in `defaultOpen`. */
4
+ id: string;
5
+ /** Always shown. Pressing it opens and closes the item, so it holds nothing clickable. */
6
+ title: React.ReactNode;
7
+ content: React.ReactNode;
8
+ }
9
+ export interface AccordionProps {
10
+ items: AccordionItem[];
11
+ /** The ids of the items that start open. */
12
+ defaultOpen?: string[];
13
+ /** Opening an item closes the one that was open. */
14
+ singleOpen?: boolean;
15
+ /** Renders each title as a heading of this level instead of plain text. */
16
+ headingLevel?: 2 | 3 | 4 | 5 | 6;
17
+ className?: string;
18
+ }
19
+ export default function Accordion({ items, defaultOpen, singleOpen, headingLevel, className, }: AccordionProps): React.JSX.Element;
@@ -0,0 +1,2 @@
1
+ export { default } from './Accordion';
2
+ export type { AccordionItem, AccordionProps } from './Accordion';
@@ -4,5 +4,14 @@ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElemen
4
4
  size?: 'small' | 'medium' | 'large';
5
5
  fullWidth?: boolean;
6
6
  children: React.ReactNode;
7
+ /** Makes it a link that looks like a button, for an action that goes to another place. */
8
+ href?: string;
9
+ target?: string;
10
+ rel?: string;
11
+ /**
12
+ * The element or component to render. Default: 'a' with `href`, else 'button'. Pass a router's
13
+ * link component with `href` to navigate without a page load: it receives `href` and the rest.
14
+ */
15
+ as?: React.ElementType;
7
16
  }
8
- export default function Button({ variant, size, fullWidth, children, className, ...props }: ButtonProps): React.JSX.Element;
17
+ export default function Button({ variant, size, fullWidth, children, className, href, target, rel, as, type, disabled, onClick, ...props }: ButtonProps): React.JSX.Element;
@@ -3,10 +3,11 @@ export interface ContainerProps {
3
3
  children: React.ReactNode;
4
4
  /**
5
5
  * The breakpoint whose width caps the container: `sm` 640px, `md` 768px, `lg` 1024px,
6
- * `xl` 1280px, `xxl` 1600px.
6
+ * `xl` 1280px, `xxl` 1600px. With none, the cap is the app's `--container-max-width`,
7
+ * or 1280px where that is not set.
7
8
  */
8
9
  size?: 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
9
10
  className?: string;
10
11
  as?: React.ElementType;
11
12
  }
12
- export default function Container({ children, size, className, as: Tag, }: ContainerProps): React.JSX.Element;
13
+ export default function Container({ children, size, className, as: Tag }: ContainerProps): React.JSX.Element;
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ export interface IconButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'aria-label' | 'aria-labelledby' | 'children'> {
3
+ /** The button's name for screen readers, and its tooltip. */
4
+ label: string;
5
+ /** The icon, such as an `<Icon>`. Decorative: the label names the button. */
6
+ icon: React.ReactNode;
7
+ variant?: 'default' | 'danger';
8
+ }
9
+ export default function IconButton({ label, icon, variant, type, title, className, ...props }: IconButtonProps): React.JSX.Element;
@@ -0,0 +1,2 @@
1
+ export { default } from './IconButton';
2
+ export type { IconButtonProps } from './IconButton';
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ export interface LevelChipProps extends Omit<React.HTMLAttributes<HTMLSpanElement>, 'children'> {
3
+ /** What the level is of, such as "React". */
4
+ label: string;
5
+ /** How many dots are filled, from 0 to `max`. */
6
+ level: number;
7
+ /** How many dots there are. Default: 5. */
8
+ max?: number;
9
+ /** What screen readers read for the dots, and their tooltip, such as "Level 4 of 5". */
10
+ levelLabel: string;
11
+ }
12
+ /** A small chip with a name and its level in dots, such as a skill and how well it is known. */
13
+ export default function LevelChip({ label, level, max, levelLabel, className, ...props }: LevelChipProps): React.JSX.Element;
@@ -0,0 +1,2 @@
1
+ export { default } from './LevelChip';
2
+ export type { LevelChipProps } from './LevelChip';
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ export interface SegmentedControlOption {
3
+ value: string;
4
+ label: React.ReactNode;
5
+ /** The label's language where it differs from the page's, as in a language's own name. */
6
+ lang?: string;
7
+ }
8
+ export interface SegmentedControlProps {
9
+ /** Shown above the options. It names the group. */
10
+ label: string;
11
+ /** Keeps the label for screen readers only. */
12
+ hideLabel?: boolean;
13
+ /** The options, in order. Two to five short ones fit best. */
14
+ options: SegmentedControlOption[];
15
+ /** The picked option's value. Give it with `onChange` to keep the pick in the app. */
16
+ value?: string;
17
+ /** The option picked at first when `value` is not given. */
18
+ defaultValue?: string;
19
+ /** Called with the value of each option the visitor picks. */
20
+ onChange?: (value: string) => void;
21
+ /** The field's name in a form. Without one, the control makes a name of its own. */
22
+ name?: string;
23
+ disabled?: boolean;
24
+ className?: string;
25
+ }
26
+ /** Picks exactly one of a few options, drawn as the parts of one control. */
27
+ export default function SegmentedControl({ label, hideLabel, options, value, defaultValue, onChange, name, disabled, className, }: SegmentedControlProps): React.JSX.Element;
@@ -0,0 +1,2 @@
1
+ export { default } from './SegmentedControl';
2
+ export type { SegmentedControlOption, SegmentedControlProps } from './SegmentedControl';
@@ -1,11 +1,18 @@
1
1
  import React from 'react';
2
2
  export interface SelectProps extends React.SelectHTMLAttributes<HTMLSelectElement> {
3
3
  label?: string;
4
- /** The text of the empty first option, such as "Select...". */
5
- placeholder: string;
4
+ /** A line under the select that describes it. */
5
+ hint?: string;
6
+ /**
7
+ * The text of an empty first option, such as "Select...". With none there is no empty option,
8
+ * for a field that always has a value.
9
+ */
10
+ placeholder?: string;
6
11
  options: {
7
12
  value: string;
8
13
  label: string;
9
14
  }[];
15
+ /** Less padding, for a field in a row of controls. The text keeps its size. */
16
+ compact?: boolean;
10
17
  }
11
- export default function Select({ label, placeholder, options, className, id, ...props }: SelectProps): React.JSX.Element;
18
+ export default function Select({ label, hint, placeholder, options, compact, className, id, 'aria-describedby': ariaDescribedBy, ...props }: SelectProps): React.JSX.Element;
@@ -3,9 +3,14 @@ export interface ShimmerImageProps extends Omit<React.ImgHTMLAttributes<HTMLImag
3
3
  src: string;
4
4
  /** Describes the picture. Pass an empty string for a decorative one. */
5
5
  alt: string;
6
+ /**
7
+ * Shown in place of the image when `src` is empty or its file cannot be loaded, such as a
8
+ * placeholder tile. Without it a broken image keeps shimmering.
9
+ */
10
+ fallback?: React.ReactNode;
6
11
  }
7
12
  /**
8
13
  * An `<img>` that fills its positioned parent, shows a shimmer while the file loads and fades the
9
14
  * picture in once it has decoded. `className` lands on the `<img>`.
10
15
  */
11
- export default function ShimmerImage({ src, alt, className, ...imageProps }: ShimmerImageProps): React.JSX.Element;
16
+ export default function ShimmerImage({ src, alt, fallback, className, onError, ...imageProps }: ShimmerImageProps): React.JSX.Element;
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ export interface SliderProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'value' | 'defaultValue' | 'min' | 'max' | 'step' | 'children'> {
3
+ /** Names the slider, and shows above it. */
4
+ label: string;
5
+ /** Keeps the label for screen readers only. */
6
+ hideLabel?: boolean;
7
+ /** The picked number. Give it with `onChange` to keep it in the app. */
8
+ value?: number;
9
+ /** The number picked at first when `value` is not given. Default: halfway. */
10
+ defaultValue?: number;
11
+ /** Default: 0. */
12
+ min?: number;
13
+ /** Default: 100. */
14
+ max?: number;
15
+ /** The distance between the numbers that can be picked, from `min`. Default: 1. */
16
+ step?: number;
17
+ /** Writes a value as text, such as "12 posts": shown, and read by screen readers. */
18
+ formatValue?: (value: number) => string;
19
+ /** Shows the value beside the label. Default: true. */
20
+ showValue?: boolean;
21
+ /** Numbers printed under the track, each where the thumb sits when it is picked. */
22
+ marks?: number[];
23
+ /** A line under the slider that describes it. */
24
+ hint?: string;
25
+ ref?: React.Ref<HTMLInputElement>;
26
+ }
27
+ /** Picks a number from a range, by dragging a thumb or with the arrow keys. */
28
+ export default function Slider({ label, hideLabel, value, defaultValue, min, max, step, formatValue, showValue, marks, hint, className, id, style, onChange, ref, 'aria-describedby': ariaDescribedBy, 'aria-valuetext': ariaValueText, ...props }: SliderProps): React.JSX.Element;
@@ -0,0 +1,2 @@
1
+ export { default } from './Slider';
2
+ export type { SliderProps } from './Slider';
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ export interface SwitchProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'role' | 'children'> {
3
+ /** Names the switch, and shows beside it. */
4
+ label: string;
5
+ /** Keeps the label for screen readers only, where the page already says what it switches. */
6
+ hideLabel?: boolean;
7
+ }
8
+ /** Turns one thing on or off, at once. For a choice sent with a form, use a Checkbox. */
9
+ export default function Switch({ label, hideLabel, className, ...props }: SwitchProps): React.JSX.Element;
@@ -0,0 +1,2 @@
1
+ export { default } from './Switch';
2
+ export type { SwitchProps } from './Switch';
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ export interface TabItem {
3
+ /** Tells the tabs apart, in `activeId` and `onChange`. */
4
+ id: string;
5
+ /** The tab's text. */
6
+ label: React.ReactNode;
7
+ /** Shown before the label. Decorative: hidden from screen readers. */
8
+ icon?: React.ReactNode;
9
+ /** What the tab's panel holds. Only the selected tab's content is rendered. */
10
+ content: React.ReactNode;
11
+ }
12
+ export interface TabsProps {
13
+ /** Names the row of tabs for screen readers, such as "Curriculum sections". */
14
+ label: string;
15
+ /** The tabs and their panels, in order. */
16
+ items: TabItem[];
17
+ /** The selected tab's id. Give it with `onChange` to keep the selection in the app. */
18
+ activeId?: string;
19
+ /** The tab selected at first when `activeId` is not given. Default: the first. */
20
+ defaultActiveId?: string;
21
+ /** Called with the id of each tab the visitor picks. */
22
+ onChange?: (id: string) => void;
23
+ className?: string;
24
+ }
25
+ /** A row of tabs, one of them selected, with that tab's panel under the row. */
26
+ export default function Tabs({ label, items, activeId, defaultActiveId, onChange, className, }: TabsProps): React.JSX.Element;
@@ -0,0 +1,2 @@
1
+ export { default } from './Tabs';
2
+ export type { TabItem, TabsProps } from './Tabs';
@@ -0,0 +1,24 @@
1
+ export interface TagGroupOption {
2
+ value: string;
3
+ label: string;
4
+ }
5
+ interface TagGroupBaseProps {
6
+ /** Shown above the tags. It names the group. */
7
+ label: string;
8
+ options: TagGroupOption[];
9
+ className?: string;
10
+ }
11
+ /** Several tags can be picked, or with `selection="single"` one at most. */
12
+ export type TagGroupProps = TagGroupBaseProps & ({
13
+ selection?: 'multiple';
14
+ /** The values picked, in the order they were picked. */
15
+ selected: string[];
16
+ onChange: (selected: string[]) => void;
17
+ } | {
18
+ selection: 'single';
19
+ selected: string | null;
20
+ /** Gets null when the picked tag is pressed again. */
21
+ onChange: (selected: string | null) => void;
22
+ });
23
+ export default function TagGroup(props: TagGroupProps): import("react").JSX.Element;
24
+ export {};
@@ -0,0 +1,2 @@
1
+ export { default } from './TagGroup';
2
+ export type { TagGroupOption, TagGroupProps } from './TagGroup';
@@ -1,5 +1,7 @@
1
1
  import React from 'react';
2
2
  export interface TextAreaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
3
3
  label?: string;
4
+ /** A line under the text area that describes it. */
5
+ hint?: string;
4
6
  }
5
- export default function TextArea({ label, className, id, ...props }: TextAreaProps): React.JSX.Element;
7
+ export default function TextArea({ label, hint, className, id, 'aria-describedby': ariaDescribedBy, ...props }: TextAreaProps): React.JSX.Element;
@@ -1,7 +1,11 @@
1
1
  import React from 'react';
2
2
  export interface TextInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
3
3
  label?: string;
4
+ /** A line under the input that describes it, such as what a password needs. */
5
+ hint?: string;
4
6
  /** Shown under the input, which it describes; the input is then marked invalid. */
5
7
  error?: string;
8
+ /** Less padding, for a field in a row of controls. The text keeps its size. */
9
+ compact?: boolean;
6
10
  }
7
- export default function TextInput({ label, error, className, id, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, ...props }: TextInputProps): React.JSX.Element;
11
+ export default function TextInput({ label, hint, error, compact, className, id, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, ...props }: TextInputProps): React.JSX.Element;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { default as Accordion } from './components/Accordion';
2
+ export type { AccordionItem, AccordionProps } from './components/Accordion';
1
3
  export { default as Button } from './components/Button';
2
4
  export type { ButtonProps } from './components/Button';
3
5
  export { default as Card } from './components/Card';
@@ -8,6 +10,10 @@ export { default as Container } from './components/Container';
8
10
  export type { ContainerProps } from './components/Container';
9
11
  export { default as Icon, ICON_NAMES } from './components/Icon';
10
12
  export type { IconName, IconProps } from './components/Icon';
13
+ export { default as IconButton } from './components/IconButton';
14
+ export type { IconButtonProps } from './components/IconButton';
15
+ export { default as LevelChip } from './components/LevelChip';
16
+ export type { LevelChipProps } from './components/LevelChip';
11
17
  export { default as Markdown } from './components/Markdown';
12
18
  export type { MarkdownProps } from './components/Markdown';
13
19
  export { default as MarkdownEditor } from './components/MarkdownEditor';
@@ -22,16 +28,26 @@ export { default as PageTransition } from './components/PageTransition';
22
28
  export type { PageTransitionProps } from './components/PageTransition';
23
29
  export { default as Section } from './components/Section';
24
30
  export type { SectionProps } from './components/Section';
31
+ export { default as SegmentedControl } from './components/SegmentedControl';
32
+ export type { SegmentedControlOption, SegmentedControlProps } from './components/SegmentedControl';
25
33
  export { default as Select } from './components/Select';
26
34
  export type { SelectProps } from './components/Select';
27
35
  export { default as ShimmerImage } from './components/ShimmerImage';
28
36
  export type { ShimmerImageProps } from './components/ShimmerImage';
29
37
  export { default as SideNav } from './components/SideNav';
30
38
  export type { SideNavGroup, SideNavItem, SideNavProps } from './components/SideNav';
39
+ export { default as Slider } from './components/Slider';
40
+ export type { SliderProps } from './components/Slider';
41
+ export { default as Switch } from './components/Switch';
42
+ export type { SwitchProps } from './components/Switch';
43
+ export { default as Tabs } from './components/Tabs';
44
+ export type { TabItem, TabsProps } from './components/Tabs';
31
45
  export { default as Tag } from './components/Tag';
32
46
  export type { TagProps } from './components/Tag';
33
47
  export { default as TagFilter } from './components/TagFilter';
34
48
  export type { TagFilterProps } from './components/TagFilter';
49
+ export { default as TagGroup } from './components/TagGroup';
50
+ export type { TagGroupOption, TagGroupProps } from './components/TagGroup';
35
51
  export { default as Text } from './components/Text';
36
52
  export type { TextProps, TextSize, TextTone, TextVariant, TextWeight } from './components/Text';
37
53
  export { default as TextArea } from './components/TextArea';