@stokr/components-library 4.0.0 → 4.0.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.
@@ -1,5 +1,5 @@
1
1
  import { ComponentType, SVGProps } from 'react';
2
- import { MaterialIconWeight } from './iconConfig';
2
+ import { MaterialIconName } from './iconConfig';
3
3
  export declare const ICON_SIZES: {
4
4
  readonly xs: 12;
5
5
  readonly sm: 16;
@@ -19,18 +19,16 @@ interface IconBaseProps {
19
19
  dataCy?: string;
20
20
  }
21
21
  export interface MaterialIconProps extends IconBaseProps {
22
- /** Material Symbols name in snake_case, e.g. `arrow_back` (see fonts.google.com/icons). */
23
- name: string;
22
+ /** Material Symbols name in snake_case, e.g. `arrow_back` (see fonts.google.com/icons). Must be registered. */
23
+ name: MaterialIconName;
24
24
  variant?: 'outlined' | 'rounded' | 'sharp';
25
25
  filled?: boolean;
26
- /** Stroke weight; needs that weight's package hosted (see `setMaterialIconsBaseUrl`). */
27
- weight?: MaterialIconWeight;
28
26
  }
29
27
  /**
30
- * Any Material Symbol by name. Each icon is a small SVG fetched (and cached) on first use, so there is no icon bundle
31
- * and no release is needed for a new icon. Where the SVGs come from: `setMaterialIconsBaseUrl`.
28
+ * A Material Symbol the app registered with `registerMaterialIcons`, drawn inline (in the server render too, no
29
+ * request) in the text colour or `color`. An unregistered icon renders nothing.
32
30
  */
33
- export declare const MaterialIcon: ({ name, variant, filled, weight, size, color, label, className, dataCy, }: MaterialIconProps) => import("react/jsx-runtime").JSX.Element;
31
+ export declare const MaterialIcon: ({ name, variant, filled, size, color, label, className, dataCy, }: MaterialIconProps) => import("react/jsx-runtime").JSX.Element;
34
32
  export interface SvgIconProps extends IconBaseProps {
35
33
  /** An SVG React component (`import Logo from './logo.svg?react'`), or the URL of a single-colour SVG. */
36
34
  svg: ComponentType<SVGProps<SVGSVGElement>> | string;
@@ -1,29 +1,28 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { MaskedIcon, IconBox } from "./MaterialIcon.styles.js";
3
- import { getMaterialIconsBaseUrl } from "./iconConfig.js";
2
+ import { createElement } from "react";
3
+ import { InlineIcon, MaskedIcon, IconBox } from "./MaterialIcon.styles.js";
4
+ import { getRegisteredMaterialIcon } from "./iconConfig.js";
4
5
  const ICON_SIZES = { xs: 12, sm: 16, md: 20, lg: 24, xl: 32 };
5
6
  const toPx = (size) => typeof size === "number" ? size : ICON_SIZES[size];
6
7
  const a11y = (label) => label ? { role: "img", "aria-label": label } : { "aria-hidden": true };
7
- const VALID_NAME = /^[a-z0-9_]+$/;
8
- const VARIANTS = ["outlined", "rounded", "sharp"];
9
8
  const cssUrl = (url) => `url("${encodeURI(url).replace(/["'()]/g, (c) => `%${c.charCodeAt(0).toString(16)}`)}")`;
10
9
  const MaterialIcon = ({
11
10
  name,
12
11
  variant = "outlined",
13
12
  filled = false,
14
- weight = 400,
15
13
  size = "lg",
16
14
  color,
17
15
  label,
18
16
  className,
19
17
  dataCy
20
18
  }) => {
21
- if (!VALID_NAME.test(name) || !VARIANTS.includes(variant)) {
19
+ const path = `${variant}/${name}${filled ? "-fill" : ""}`;
20
+ const svg = getRegisteredMaterialIcon(path);
21
+ if (!svg) {
22
22
  return null;
23
23
  }
24
- const url = `${getMaterialIconsBaseUrl(weight)}/${variant}/${name}${filled ? "-fill" : ""}.svg`;
25
24
  return /* @__PURE__ */ jsx(
26
- MaskedIcon,
25
+ InlineIcon,
27
26
  {
28
27
  ...a11y(label),
29
28
  className,
@@ -31,7 +30,7 @@ const MaterialIcon = ({
31
30
  "data-icon": name,
32
31
  $size: toPx(size),
33
32
  $color: color,
34
- style: { "--icon-url": cssUrl(url) }
33
+ children: createElement(svg, { "aria-hidden": true, focusable: false })
35
34
  }
36
35
  );
37
36
  };
@@ -2,6 +2,11 @@ export declare const IconBox: import('styled-components/dist/types').IStyledComp
2
2
  $size: number;
3
3
  $color?: string;
4
4
  }>> & string;
5
+ /** A registered Material Symbol drawn inline; the files have no fill, so it takes the text colour. */
6
+ export declare const InlineIcon: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components').FastOmit<import('styled-components').FastOmit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "$color" | "$size"> & {
7
+ $size: number;
8
+ $color?: string;
9
+ }, never>> & string;
5
10
  /** Paints the SVG at `--icon-url` in the text colour, so any colour works without touching the file. */
6
11
  export declare const MaskedIcon: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components').FastOmit<import('styled-components').FastOmit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "$color" | "$size"> & {
7
12
  $size: number;
@@ -14,6 +14,11 @@ const IconBox = styled.span`
14
14
  height: 100%;
15
15
  }
16
16
  `;
17
+ const InlineIcon = styled(IconBox)`
18
+ > svg {
19
+ fill: currentColor;
20
+ }
21
+ `;
17
22
  const MaskedIcon = styled(IconBox)`
18
23
  background-color: currentColor;
19
24
  -webkit-mask: var(--icon-url) center / contain no-repeat;
@@ -21,5 +26,6 @@ const MaskedIcon = styled(IconBox)`
21
26
  `;
22
27
  export {
23
28
  IconBox,
29
+ InlineIcon,
24
30
  MaskedIcon
25
31
  };
@@ -1,3 +1,24 @@
1
- export declare function setMaterialIconsBaseUrl(url: string): void;
2
- export type MaterialIconWeight = 100 | 200 | 300 | 400 | 500 | 600 | 700;
3
- export declare function getMaterialIconsBaseUrl(weight?: MaterialIconWeight): string;
1
+ import { ComponentType, SVGProps } from 'react';
2
+ /**
3
+ * Icon names an app allows. Empty here: an app narrows `MaterialIcon`'s `name` to the icons it registered:
4
+ *
5
+ * declare module '@stokr/components-library' { interface MaterialIconRegistry { name: 'home' | 'download' } }
6
+ */
7
+ export interface MaterialIconRegistry {
8
+ }
9
+ export type MaterialIconName = MaterialIconRegistry extends {
10
+ name: infer K extends string;
11
+ } ? K : string;
12
+ type SvgComponent = ComponentType<SVGProps<SVGSVGElement>>;
13
+ /**
14
+ * Registers the Material Symbols an app uses, as SVG components keyed `<variant>/<name>` (`-fill` for filled): the
15
+ * paths in the `@material-symbols/svg-<weight>` packages. Only these are bundled; `MaterialIcon` draws them inline.
16
+ * Call once at module scope in an entry shared by server and client; with Module Federation the host's call covers
17
+ * the remotes (the library is a shared singleton).
18
+ *
19
+ * import home from '@material-symbols/svg-400/outlined/home.svg?react'
20
+ * registerMaterialIcons({ 'outlined/home': home })
21
+ */
22
+ export declare function registerMaterialIcons(icons: Record<string, SvgComponent>): void;
23
+ export declare function getRegisteredMaterialIcon(key: string): SvgComponent;
24
+ export {};
@@ -1,11 +1,11 @@
1
- let baseUrl = "https://cdn.jsdelivr.net/npm/@material-symbols/svg-{weight}@0.48.0";
2
- function setMaterialIconsBaseUrl(url) {
3
- baseUrl = url.replace(/\/+$/, "");
1
+ const registered = /* @__PURE__ */ new Map();
2
+ function registerMaterialIcons(icons) {
3
+ for (const [key, svg] of Object.entries(icons)) registered.set(key, svg);
4
4
  }
5
- function getMaterialIconsBaseUrl(weight = 400) {
6
- return baseUrl.replace("{weight}", String(weight));
5
+ function getRegisteredMaterialIcon(key) {
6
+ return registered.get(key);
7
7
  }
8
8
  export {
9
- getMaterialIconsBaseUrl,
10
- setMaterialIconsBaseUrl
9
+ getRegisteredMaterialIcon,
10
+ registerMaterialIcons
11
11
  };
@@ -1,5 +1,5 @@
1
- import { ReactNode } from 'react';
2
- export interface SectionProps {
1
+ import { HTMLAttributes, ReactNode } from 'react';
2
+ export interface SectionProps extends Omit<HTMLAttributes<HTMLElement>, 'title' | 'children' | 'onToggle'> {
3
3
  title?: ReactNode;
4
4
  children?: ReactNode;
5
5
  /** `plain` sits on the page background instead of in a card. */
@@ -29,4 +29,4 @@ export interface SectionProps {
29
29
  /**
30
30
  * A titled content block: a card (or plain) with a header rule, optionally collapsible and with a loading state.
31
31
  */
32
- export declare const Section: ({ title, children, variant, elevated, collapsible: collapsibleProp, open: openProp, defaultOpen, onToggle, loading, skeletonRows, headingLevel, id, className, dataCy, }: SectionProps) => import("react/jsx-runtime").JSX.Element;
32
+ export declare const Section: import('react').ForwardRefExoticComponent<SectionProps & import('react').RefAttributes<HTMLElement>>;
@@ -1,5 +1,5 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
- import { useState, useId } from "react";
2
+ import { forwardRef, useState, useId } from "react";
3
3
  import { ArrowSimple } from "../icons/ArrowSimple.js";
4
4
  import { inertProp } from "../../utils/inertProp.js";
5
5
  import { Chevron } from "../Collapsible/Collapsible.styles.js";
@@ -7,7 +7,7 @@ import { SkeletonLines } from "../Skeleton/Skeleton.js";
7
7
  import { useMediaQuery } from "../../hooks/useMediaQuery.js";
8
8
  import { mediaQuery } from "../../styles/rwd.js";
9
9
  import { SectionRoot, SectionHeader, SectionHeading, SectionToggle, SectionBody, SectionBodyClip, SectionBodyInner } from "./Section.styles.js";
10
- const Section = ({
10
+ const Section = forwardRef(function Section2({
11
11
  title,
12
12
  children,
13
13
  variant = "card",
@@ -21,8 +21,9 @@ const Section = ({
21
21
  headingLevel = "h2",
22
22
  id,
23
23
  className,
24
- dataCy
25
- }) => {
24
+ dataCy,
25
+ ...rest
26
+ }, ref) {
26
27
  const collapsible = Boolean(collapsibleProp) && Boolean(title);
27
28
  const desktopOpen = collapsibleProp === "desktop-open";
28
29
  const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
@@ -44,6 +45,8 @@ const Section = ({
44
45
  return /* @__PURE__ */ jsxs(
45
46
  SectionRoot,
46
47
  {
48
+ ...rest,
49
+ ref,
47
50
  id,
48
51
  className,
49
52
  "data-cy": dataCy,
@@ -74,7 +77,7 @@ const Section = ({
74
77
  ]
75
78
  }
76
79
  );
77
- };
80
+ });
78
81
  export {
79
82
  Section
80
83
  };
@@ -1,5 +1,6 @@
1
1
  import { HTMLAttributes } from 'react';
2
- export declare const loaderGif: string;
2
+ /** The loading animation as animated WebP (~18 KB, the GIF is ~580 KB); a stable URL so browsers cache it. */
3
+ export declare const loaderGif = "https://res.cloudinary.com/stokr/image/upload/f_webp,fl_awebp,q_auto/v1575035788/Static/stokr_loader_white_400x400_egnhgb.gif";
3
4
  export interface StokrLoaderProps {
4
5
  /** Leaves the top 97px (the header) visible instead of covering the whole screen. */
5
6
  noFullscreen?: boolean;
@@ -1,6 +1,6 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
2
  import styled, { keyframes } from "styled-components";
3
- const loaderGif = `https://res.cloudinary.com/stokr/image/upload/f_auto,q_auto/v1575035788/Static/stokr_loader_white_400x400_egnhgb.gif?a=${Math.random()}`;
3
+ const loaderGif = "https://res.cloudinary.com/stokr/image/upload/f_webp,fl_awebp,q_auto/v1575035788/Static/stokr_loader_white_400x400_egnhgb.gif";
4
4
  const CenterFullWidth = styled.div`
5
5
  width: 100%;
6
6
  height: 100%;
package/dist/index.d.ts CHANGED
@@ -51,8 +51,8 @@ export type { SkeletonProps, SkeletonLinesProps, SkeletonStatusProps } from './c
51
51
  export { Collapsible } from './components/Collapsible/Collapsible'
52
52
  export { MaterialIcon, SvgIcon, ICON_SIZES } from './components/MaterialIcon/MaterialIcon'
53
53
  export type { MaterialIconProps, SvgIconProps, IconSize } from './components/MaterialIcon/MaterialIcon'
54
- export { setMaterialIconsBaseUrl, getMaterialIconsBaseUrl } from './components/MaterialIcon/iconConfig'
55
- export type { MaterialIconWeight } from './components/MaterialIcon/iconConfig'
54
+ export { registerMaterialIcons } from './components/MaterialIcon/iconConfig'
55
+ export type { MaterialIconName, MaterialIconRegistry } from './components/MaterialIcon/iconConfig'
56
56
  export type { CollapsibleProps } from './components/Collapsible/Collapsible'
57
57
  export { Section } from './components/Section/Section'
58
58
  export type { SectionProps } from './components/Section/Section'
@@ -85,7 +85,7 @@ export {
85
85
  useCopyToClipboard,
86
86
  CopyToClipBoardTooltip,
87
87
  } from './utils/copyToClipboard'
88
- export type { WithCopyToClipboardOptions } from './utils/copyToClipboard'
88
+ export type { WithCopyToClipboardOptions, CopyToClipboardProps } from './utils/copyToClipboard'
89
89
  export {
90
90
  useMobileView,
91
91
  useContainerSize,
package/dist/index.js CHANGED
@@ -46,7 +46,7 @@ import { SideModalBody, SideModalFooter, SideModalHeader } from "./components/Mo
46
46
  import { Skeleton, SkeletonLines, SkeletonStatus } from "./components/Skeleton/Skeleton.js";
47
47
  import { Collapsible } from "./components/Collapsible/Collapsible.js";
48
48
  import { ICON_SIZES, MaterialIcon, SvgIcon } from "./components/MaterialIcon/MaterialIcon.js";
49
- import { getMaterialIconsBaseUrl, setMaterialIconsBaseUrl } from "./components/MaterialIcon/iconConfig.js";
49
+ import { registerMaterialIcons } from "./components/MaterialIcon/iconConfig.js";
50
50
  import { Section } from "./components/Section/Section.js";
51
51
  import { CardTabs, TabPanel } from "./components/CardTabs/CardTabs.js";
52
52
  import { TabCard, TabCardBody, TabHighlightBase, tabColorTransition } from "./components/CardTabs/CardTabs.styles.js";
@@ -92,7 +92,7 @@ import { AnimatedSpan, LoadingDots, StokrLoader, StokrLoaderBox, loaderGif } fro
92
92
  import { InfoBox } from "./components/InfoBox/InfoBox.js";
93
93
  import { IdentityCountryRow, IdentityResidencyItem, IdentitySectionHeader } from "./components/IdentityInfo/IdentityInfo.js";
94
94
  import { Inner, Outer, ThumbH, ThumbV, TrackH, TrackV } from "./components/ComponentScroll/ComponentScroll.styles.js";
95
- import { CopyToClipBoardTooltip, useCopyToClipboard, withCopyToClipboard } from "./utils/copyToClipboard.js";
95
+ import { CopyToClipBoardTooltip, CopyToClipboard, useCopyToClipboard, withCopyToClipboard } from "./utils/copyToClipboard.js";
96
96
  import { cooldownHOC, useComponentVisible, useContainerSize, useCooldown, useMobileView, usePrevious } from "./utils/customHooks.js";
97
97
  import { fixDecimals, formatDisplayNumber } from "./utils/fix-decimals.js";
98
98
  import { CURRENCY_CONFIG, formatAmountForDisplay, formatCurrencyValue, getCurrencyConfig, getCurrencyIcon, getCurrencySymbol, getProjectCurrencySign } from "./utils/formatCurrencyValue.js";
@@ -125,7 +125,6 @@ import { ArrowSimple } from "./components/icons/ArrowSimple.js";
125
125
  import { BackButtonIcon, StyledBackButton, StyledBackButtonExternal, StyledWindowBackButton } from "./components/BackButton/BackButton.styles.js";
126
126
  import { Breakdown } from "./components/breakdown/Breakdown.js";
127
127
  import { default as default9 } from "./components/SvgIcons/CapsLockSvg.js";
128
- import { CopyToClipboard } from "react-copy-to-clipboard";
129
128
  import { FaqContent, FaqDropdownIcon, FaqItem, FaqItems, FaqText, FaqTitle } from "./components/FAQ/FAQ.styles.js";
130
129
  import * as Flags from "country-flag-icons/react/3x2";
131
130
  import { FormContainer, FormError, FormField, FormInfo } from "./components/Form/Form.styles.js";
@@ -397,7 +396,6 @@ export {
397
396
  getCurrencyConfig,
398
397
  getCurrencyIcon,
399
398
  getCurrencySymbol,
400
- getMaterialIconsBaseUrl,
401
399
  getMedia,
402
400
  getPasswordCriteria,
403
401
  getPasswordEntropy,
@@ -423,6 +421,7 @@ export {
423
421
  projectTokenUnit,
424
422
  projectUnit,
425
423
  radius,
424
+ registerMaterialIcons,
426
425
  resolveCopy,
427
426
  roundTo,
428
427
  default5 as rwd,
@@ -431,7 +430,6 @@ export {
431
430
  saveAs,
432
431
  scrollToElement,
433
432
  setCopySource,
434
- setMaterialIconsBaseUrl,
435
433
  default2 as shortenAddress,
436
434
  showProgress,
437
435
  showSuccess,
@@ -1,8 +1,19 @@
1
- import { ComponentType } from 'react';
2
- import { CopyToClipboard } from 'react-copy-to-clipboard';
1
+ import { ComponentType, ReactElement } from 'react';
3
2
  import { copyTextToClipboard } from './copy-text-to-clipboard';
4
3
  import { CopyToClipboardTooltip } from '../components/CopyToClipboardTooltip/CopyToClipboardTooltip';
5
4
  export { copyTextToClipboard };
5
+ export interface CopyToClipboardProps {
6
+ text: string;
7
+ onCopy?: (text: string, result: boolean) => void;
8
+ options?: {
9
+ debug?: boolean;
10
+ message?: string;
11
+ format?: string;
12
+ };
13
+ children: ReactElement;
14
+ }
15
+ /** `react-copy-to-clipboard`'s component, typed here so apps don't need that package's types. */
16
+ export declare const CopyToClipboard: ComponentType<CopyToClipboardProps>;
6
17
  export type WithCopyToClipboardOptions = {
7
18
  /** Prop holding the text to copy. Default 'text'. */
8
19
  textProp?: string;
@@ -24,4 +35,3 @@ export declare const useCopyToClipboard: (text?: string) => {
24
35
  */
25
36
  export declare const CopyToClipBoardTooltip: ({ value, buttonStyle, onCopy, children, copiedLabel, idleLabel, resetAfter, }: import('..').CopyToClipboardTooltipProps) => import("react/jsx-runtime").JSX.Element;
26
37
  export { CopyToClipboardTooltip };
27
- export { CopyToClipboard };
@@ -1,9 +1,9 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import React__default from "react";
3
- import { CopyToClipboard } from "react-copy-to-clipboard";
4
- import { CopyToClipboard as CopyToClipboard2 } from "react-copy-to-clipboard";
3
+ import { CopyToClipboard as CopyToClipboard$1 } from "react-copy-to-clipboard";
5
4
  import { copyTextToClipboard } from "./copy-text-to-clipboard.js";
6
5
  import { CopyToClipboardTooltip } from "../components/CopyToClipboardTooltip/CopyToClipboardTooltip.js";
6
+ const CopyToClipboard = CopyToClipboard$1;
7
7
  const withCopyToClipboard = (WrappedComponent, options = {}) => {
8
8
  const { textProp = "text", onCopyProp = "onCopy", onErrorProp = "onError" } = options;
9
9
  return function CopyToClipboardWrapper(props) {
@@ -40,7 +40,7 @@ const useCopyToClipboard = (text) => {
40
40
  const CopyToClipBoardTooltip = CopyToClipboardTooltip;
41
41
  export {
42
42
  CopyToClipBoardTooltip,
43
- CopyToClipboard2 as CopyToClipboard,
43
+ CopyToClipboard,
44
44
  CopyToClipboardTooltip,
45
45
  copyTextToClipboard,
46
46
  useCopyToClipboard,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stokr/components-library",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "STOKR - Components Library",
5
5
  "author": "Bilal Hodzic <bilal@stokr.io>",
6
6
  "license": "MIT",
@@ -83,6 +83,7 @@
83
83
  "@chromatic-com/storybook": "^5.3.1",
84
84
  "@eslint-react/eslint-plugin": "^1.53.1",
85
85
  "@eslint/js": "^9.39.2",
86
+ "@material-symbols/svg-400": "0.48.0",
86
87
  "@storybook/addon-docs": "^10.6.0",
87
88
  "@storybook/addon-links": "^10.6.0",
88
89
  "@storybook/builder-vite": "^10.6.0",