@protonradio/proton-ui 0.1.42 → 0.2.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
@@ -1,64 +1,50 @@
1
- # Proton UI
2
-
3
- ![](./.readme.gif)
4
-
5
- ```
6
- npm run storybook
7
- ```
8
-
9
- ### Publishing Updates to NPM
10
- ```
11
- npm run build
12
- npm version <new_version> // increment version in package.json accordingly using semver
13
- npm publish
14
- ```
15
-
16
- ### Themes
17
- This library supports themes for the various applications that use it. Ideally, we would unify our app designs, but until then themes is a way to support different design patterns using the same api.
18
-
19
- #### Adding a Theme
20
- The current supported themes can be found in the `src/themes/config.ts`. To add a new theme, create a new attribute on the `THEME_CONFIG` object following the pattern `[themeName]: [themeClassName]`.
21
-
22
- When applying to a project, you can import available themes using `THEME_CONFIG` from this library and apply the theme an outer div on the application. See below for an example.
23
-
24
- ```jsx
25
- import { THEME_CONFIG } from '@protonradio/proton-ui'
26
-
27
- function MyApp({ Component, pageProps }) {
28
- return (
29
- <div className={THEME_CONFIG.ReleaseLinks}> {/* Set your theme here */}
30
- <Component {...pageProps} />
31
- </div>
32
- );
33
- }
34
- ```
35
-
36
- #### Styling for a theme
37
- To apply theme specific styles in a component, you can select using the class name that belongs to the theme (see `src/themes/config.ts`). For example, to apply a style to the `ReleaseLinks` theme, you can use the following css.
38
-
39
- Theme specific css should be placed in the `src/themes` directory in a unqiue file for the theme and component. The file naming convention should be `[componentName].[themeClassName].css`.
40
-
41
- ```css
42
- .ReleaseLinks .myComponent {
43
- background-color: red;
44
- }
45
- ```
46
-
47
- #### Overriding CSS Variables
48
- Components reuse common colors across components and, in an attempt to unify these colors under common variables, common component attributes have been defined in globals.css and can be overridden at the theme level (ex: src/themes/release-links/index.css`.
49
-
50
- These should be used where possible so that if we decide to change styling accross the component library we can do so in just a few places.
51
-
52
- This also makes it easier for overriding some component styles from within a project to something more dynamic. In the case of the `ReleaseLinks` app, we calculate some background colors from the album artwork. Because of this we want to override the background color of certain elements in the `ReleaseLinks` theme with a css variable.
53
-
54
- An example of this might look like:
55
-
56
- ```js
57
- document.documentElement.style.setProperty(
58
- "--proton-control-background",
59
- buttonBackgroundColor
60
- );
61
- ```
62
-
63
- ### Recommended Reading
64
- - https://www.gabe.pizza/notes-on-component-libraries/
1
+ # Proton UI
2
+
3
+ ![](./.readme.gif)
4
+
5
+ ```
6
+ npm run storybook
7
+ ```
8
+
9
+ ### Publishing Updates to NPM
10
+
11
+ ```
12
+ npm run build
13
+ npm version <new_version> // increment version in package.json accordingly using semver
14
+ npm publish
15
+ ```
16
+
17
+ ### Themes
18
+
19
+ This library supports themes for the various applications that use it. Ideally, we would unify our app designs, but until then themes is a way to support different design patterns using the same api.
20
+
21
+ #### Adding a Theme
22
+
23
+ The current supported themes can be found in the `src/themes/config.ts`. To add a new theme, create a new attribute on the `THEMES` object following the pattern `[themeName]: [themeClassName]`.
24
+
25
+ When applying to a project, you can import available themes using `THEMES` from this library and apply the theme an outer div on the application. See below for an example.
26
+
27
+ ```jsx
28
+ function MyApp({ Component, pageProps }) {
29
+ return (
30
+ <ThemeProvider theme={THEMES.DARK}>
31
+ <Component {...pageProps} />
32
+ </ThemeProvider>
33
+ );
34
+ }
35
+ ```
36
+
37
+ #### Styling for a theme
38
+
39
+ To apply theme specific styles in a component, we set theme specific css variables in the `src/themes/config.ts` file, in `generateThemeCssVariables` function. If you need more control, you can add either use the `useTheme` hook to manipulate the DOM, or you can use css selectors that reference the wrapping theme class.
40
+
41
+ For example, to apply a style to the dark theme, you can use the following css.
42
+ ```css
43
+ .proton-ui__theme--dark .myComponent {
44
+ background-color: red;
45
+ }
46
+ ```
47
+
48
+ ### Recommended Reading
49
+
50
+ - https://www.gabe.pizza/notes-on-component-libraries/
package/dist/icons.svg ADDED
@@ -0,0 +1,11 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
2
+ <defs>
3
+ <symbol id="external-link" viewBox="0 0 512 512">
4
+ <path d="M384 224v184a40 40 0 01-40 40H104a40 40 0 01-40-40V168a40 40 0 0140-40h167.48M336 64h112v112M224 288L440 72" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"/>
5
+ </symbol>
6
+
7
+ <symbol id="caret-down" viewBox="0 0 512 512">
8
+ <path fill="currentColor" d="M233.4 406.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L256 338.7L86.6 169.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l192 192z"/>
9
+ </symbol>
10
+ </defs>
11
+ </svg>
@@ -1,16 +1,21 @@
1
- import type { AriaDialogProps } from 'react-aria';
1
+ import { AriaDialogProps } from 'react-aria';
2
2
  import type { AriaPopoverProps } from 'react-aria';
3
3
  import { AriaSelectProps } from 'react-aria';
4
+ import { AriaTableProps } from 'react-aria';
4
5
  import { ColumnProps } from '@react-stately/table';
5
6
  import { JSX as JSX_2 } from 'react/jsx-runtime';
6
7
  import { OverlayTriggerProps } from 'react-stately';
7
8
  import { OverlayTriggerState } from 'react-stately';
8
9
  import { PressEvent } from 'react-aria';
9
10
  import { default as React_2 } from 'react';
11
+ import { ReactNode } from 'react';
10
12
  import { Row } from '@react-stately/table';
11
13
  import { Section } from '@react-stately/table';
12
14
  import { TableBody } from '@react-stately/table';
13
15
  import { TableHeader } from '@react-stately/table';
16
+ import { TableStateProps } from 'react-stately';
17
+ import { TooltipProps as TooltipProps_2 } from 'react-aria-components';
18
+ import { TooltipTriggerComponentProps } from 'react-aria-components';
14
19
 
15
20
  export declare function Button(props: ButtonProps): JSX_2.Element;
16
21
 
@@ -62,7 +67,7 @@ declare interface ButtonProps {
62
67
  /**
63
68
  * The button's visual aesthetic.
64
69
  */
65
- variant?: "primary" | "secondary" | "danger" | "rl-primary";
70
+ variant?: "primary" | "secondary" | "danger";
66
71
  /**
67
72
  * Should the button be non-interactive?
68
73
  */
@@ -79,10 +84,6 @@ declare interface ButtonProps {
79
84
  * The content to display within the button.
80
85
  */
81
86
  children?: React.ReactNode;
82
- /**
83
- * Optionally pass a custom ref to the button.
84
- */
85
- buttonRef?: React.MutableRefObject<any>;
86
87
  }
87
88
 
88
89
  export declare const Cell: <T>(props: ProtonColumnProps<T>) => JSX_2.Element;
@@ -99,9 +100,13 @@ declare interface DialogProps extends AriaDialogProps {
99
100
  children: React.ReactNode;
100
101
  }
101
102
 
102
- export declare function Icon(props: IconProps): JSX_2.Element;
103
+ export declare const generateThemeCssVariables: (baseColor: RGBArray | null) => Record<Theme, ThemeVariables>;
104
+
105
+ export declare const generateThemedRGBArray: (baseColor: RGBArray | null) => RGBArray;
106
+
107
+ export declare function Icon(props: Omit<IconProps, "svgContent">): JSX_2.Element;
103
108
 
104
- declare type IconID = "external-link" | "caret-down" | "chevron-down";
109
+ declare type IconID = "external-link" | "caret-down";
105
110
 
106
111
  declare interface IconProps {
107
112
  /**
@@ -123,6 +128,9 @@ export declare function Popover({ children, state, arrow, offset, ...props }: Po
123
128
  /**
124
129
  * Popover is an unstyled popover component that handles positioning. It should be used
125
130
  * with the Dialog component to provide a styled popover.
131
+ *
132
+ * A popover displays interactive content in context with a trigger element.
133
+ * A tooltip displays a description of an element on hover or focus.
126
134
  */
127
135
  declare interface PopoverProps extends Omit<AriaPopoverProps, "popoverRef"> {
128
136
  /**
@@ -147,6 +155,8 @@ export declare interface ProtonColumnProps<T> extends ColumnProps<T> {
147
155
  align?: "left" | "center" | "right";
148
156
  }
149
157
 
158
+ export declare type RGBArray = [number, number, number];
159
+
150
160
  export { Row }
151
161
 
152
162
  export { Section }
@@ -156,7 +166,7 @@ export declare const Select: {
156
166
  Option: any;
157
167
  };
158
168
 
159
- declare function SelectMenu<T extends object>(props: SelectProps<T>): JSX_2.Element;
169
+ declare function SelectMenu<T extends object>({ label, name, isDisabled, ...props }: SelectProps<T>): JSX_2.Element;
160
170
 
161
171
  declare interface SelectProps<T> extends AriaSelectProps<T> {
162
172
  label?: string;
@@ -200,17 +210,71 @@ declare interface SwitchProps {
200
210
  children?: React.ReactNode;
201
211
  }
202
212
 
203
- export declare function Table(props: any): JSX_2.Element;
213
+ export declare function Table(props: TableProps): JSX_2.Element;
204
214
 
205
215
  export { TableBody }
206
216
 
207
217
  export { TableHeader }
208
218
 
209
- export declare const THEME_CONFIG: {
210
- readonly ReleaseLinks: "rl-theme";
211
- readonly ProtonRadio: "client-theme";
219
+ declare type TableProps = AriaTableProps & TableStateProps<object>;
220
+
221
+ export declare type Theme = (typeof THEMES)[keyof typeof THEMES];
222
+
223
+ export declare const THEME_CLASSES: {
224
+ dark: string;
225
+ light: string;
226
+ };
227
+
228
+ declare interface ThemeContextType {
229
+ theme: Theme;
230
+ className: string;
231
+ style: ReturnType<typeof generateThemeCssVariables>[Theme];
232
+ baseColor: RGBArray;
233
+ themedRGBArray: RGBArray;
234
+ }
235
+
236
+ export declare const ThemeProvider: React_2.FC<ThemeProviderProps>;
237
+
238
+ declare interface ThemeProviderProps {
239
+ theme: Theme;
240
+ children: ReactNode;
241
+ baseColor?: RGBArray;
242
+ }
243
+
244
+ export declare const THEMES: {
245
+ readonly DARK: "dark";
246
+ readonly LIGHT: "light";
212
247
  };
213
248
 
249
+ export declare interface ThemeVariables {
250
+ "--proton-control-background": string;
251
+ "--proton-text-color": string;
252
+ "--proton-control-border": string;
253
+ }
254
+
255
+ export declare function Tooltip({ children, arrow, ...props }: TooltipProps): JSX_2.Element;
256
+
257
+ export declare interface TooltipProps extends Omit<TooltipProps_2, "children"> {
258
+ children: React.ReactNode;
259
+ arrow?: boolean;
260
+ }
261
+
262
+ /**
263
+ * Proton's TooltipTrigger component deviates from the Aria TooltipTrigger in that on mobile,
264
+ * the trigger also opens the tooltip on click as well as hover & focus. This is to improve
265
+ * accessibility and usability on mobile.
266
+ *
267
+ * If you wish to disable the trigger click feature, you can set the `disableTriggerClick` prop.
268
+ * This is useful when using an info only Tooltip that might wrap a clickable element.
269
+ */
270
+ export declare function TooltipTrigger({ children, delay, closeDelay, isDisabled, defaultOpen, onOpenChange, disableTriggerClick, content, ...tooltipProps }: TooltipTriggerProps): JSX_2.Element;
271
+
272
+ declare interface TooltipTriggerProps extends TooltipProps, TooltipTriggerComponentProps {
273
+ children: React.ReactNode;
274
+ content: string;
275
+ disableTriggerClick?: boolean;
276
+ }
277
+
214
278
  /**
215
279
  * Hook for creating a popover trigger. This hook manages the state and events for the popover
216
280
  * and popover trigger. For examples see Popover.stories.tsx.
@@ -222,4 +286,6 @@ export declare function usePopoverTrigger(props?: OverlayTriggerProps): {
222
286
  state: any;
223
287
  };
224
288
 
289
+ export declare const useTheme: () => ThemeContextType;
290
+
225
291
  export { }