@phillips/seldon 1.112.1 → 1.113.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.
@@ -11,7 +11,7 @@ export interface ButtonProps extends React.HTMLAttributes<HTMLButtonElement | HT
11
11
  /**
12
12
  * Optional click handler
13
13
  */
14
- onClick?: React.MouseEventHandler<HTMLButtonElement> | undefined;
14
+ onClick?: React.MouseEventHandler<HTMLButtonElement | HTMLAnchorElement> | undefined;
15
15
  /**
16
16
  * Is this the principal call to action on the page?
17
17
  */
@@ -32,6 +32,10 @@ export interface ButtonProps extends React.HTMLAttributes<HTMLButtonElement | HT
32
32
  * The target of the link (e.g. _blank). To be combined with href.
33
33
  */
34
34
  target?: string;
35
+ /**
36
+ * prefetch the link
37
+ */
38
+ prefetch?: 'none' | 'intent' | 'render' | 'viewport';
35
39
  }
36
40
  /**
37
41
  * ## Overview
@@ -1,61 +1,75 @@
1
- import { jsx as f } from "react/jsx-runtime";
1
+ import { jsxs as f, Fragment as k, jsx as o } from "react/jsx-runtime";
2
2
  import p from "../../node_modules/classnames/index.js";
3
- import { getCommonProps as c } from "../../utils/index.js";
4
- import { ButtonVariants as b } from "./types.js";
5
- import { forwardRef as d } from "react";
6
- const B = d(
3
+ import { getCommonProps as N } from "../../utils/index.js";
4
+ import { ButtonVariants as v } from "./types.js";
5
+ import { forwardRef as x, useState as P } from "react";
6
+ const j = x(
7
7
  ({
8
- variant: s = b.primary,
9
- children: t,
10
- className: r,
11
- isIconLast: a = !1,
12
- type: u = "button",
13
- isDisabled: $ = !1,
14
- href: m,
15
- target: e,
8
+ variant: r = v.primary,
9
+ children: s,
10
+ className: a,
11
+ isIconLast: l = !1,
12
+ type: $ = "button",
13
+ isDisabled: b = !1,
14
+ href: t,
15
+ target: i,
16
+ prefetch: m = "none",
16
17
  ...n
17
- }, l) => {
18
- const { className: o, ...i } = c(n, "Button");
19
- return m ? /* @__PURE__ */ f(
20
- "a",
21
- {
22
- ...i,
23
- ref: l,
24
- href: m,
25
- className: p(
26
- `${o}`,
27
- `${o}--${s}`,
18
+ }, d) => {
19
+ const { className: e, ...c } = N(n, "Button"), [B, C] = P(!1);
20
+ if (t) {
21
+ const u = () => /* @__PURE__ */ f(k, { children: [
22
+ /* @__PURE__ */ o("link", { "data-testid": "prefetch-link", rel: "prefetch", href: t }),
23
+ /* @__PURE__ */ o("link", { "data-testid": "modulepreload-link", rel: "modulepreload", href: t })
24
+ ] });
25
+ return /* @__PURE__ */ f(k, { children: [
26
+ /* @__PURE__ */ o(
27
+ "a",
28
28
  {
29
- [`${o}--icon-last`]: a
30
- },
31
- r
29
+ ...c,
30
+ ref: d,
31
+ href: t,
32
+ className: p(
33
+ `${e}`,
34
+ `${e}--${r}`,
35
+ {
36
+ [`${e}--icon-last`]: l
37
+ },
38
+ a
39
+ ),
40
+ target: i,
41
+ rel: i === "_blank" ? "noopener noreferrer" : void 0,
42
+ onMouseOver: () => C(!0),
43
+ onClick: n.onClick,
44
+ children: s
45
+ }
32
46
  ),
33
- target: e,
34
- rel: e === "_blank" ? "noopener noreferrer" : void 0,
35
- children: t
36
- }
37
- ) : /* @__PURE__ */ f(
38
- "button",
39
- {
40
- ...i,
41
- ref: l,
42
- type: u,
43
- className: p(
44
- `${o}`,
45
- `${o}--${s}`,
46
- {
47
- [`${o}--icon-last`]: a
48
- },
49
- r
50
- ),
51
- disabled: $,
52
- ...n,
53
- children: t
54
- }
55
- );
47
+ m === "intent" && B && /* @__PURE__ */ o(u, {}),
48
+ m === "render" && /* @__PURE__ */ o(u, {})
49
+ ] });
50
+ } else
51
+ return /* @__PURE__ */ o(
52
+ "button",
53
+ {
54
+ ...c,
55
+ ref: d,
56
+ type: $,
57
+ className: p(
58
+ `${e}`,
59
+ `${e}--${r}`,
60
+ {
61
+ [`${e}--icon-last`]: l
62
+ },
63
+ a
64
+ ),
65
+ disabled: b,
66
+ ...n,
67
+ children: s
68
+ }
69
+ );
56
70
  }
57
71
  );
58
- B.displayName = "Button";
72
+ j.displayName = "Button";
59
73
  export {
60
- B as default
74
+ j as default
61
75
  };
@@ -24,6 +24,13 @@ export declare const ButtonAsLink: {
24
24
  size: string;
25
25
  };
26
26
  };
27
+ export declare const ButtonAsLinkWithPrefetch: {
28
+ (props: ButtonProps): import("react/jsx-runtime").JSX.Element;
29
+ args: {
30
+ variant: ButtonVariants;
31
+ size: string;
32
+ };
33
+ };
27
34
  export declare const Playground: {
28
35
  args: {
29
36
  children: string;
@@ -1,3 +1,4 @@
1
+ import { ButtonProps } from '../Button/Button';
1
2
  import { ButtonVariants } from '../Button/types';
2
3
  export interface IconButtonProps extends Omit<React.HTMLAttributes<HTMLButtonElement>, 'children'> {
3
4
  /**
@@ -12,6 +13,18 @@ export interface IconButtonProps extends Omit<React.HTMLAttributes<HTMLButtonEle
12
13
  * Should the button be disabled?
13
14
  */
14
15
  isDisabled?: boolean;
16
+ /**
17
+ * The href of the button. This will make the button render as an anchor tag.
18
+ */
19
+ href?: ButtonProps['href'];
20
+ /**
21
+ * The target of the link (e.g. _blank). To be combined with href.
22
+ */
23
+ target?: ButtonProps['target'];
24
+ /**
25
+ * The prefetch of the link.
26
+ */
27
+ prefetch?: ButtonProps['prefetch'];
15
28
  }
16
29
  declare const IconButton: ({ children, variant, isDisabled, className, ...props }: IconButtonProps) => import("react/jsx-runtime").JSX.Element;
17
30
  export default IconButton;
@@ -1,4 +1,5 @@
1
1
  import { default as React, ComponentProps } from 'react';
2
+ import { ButtonProps } from '../Button/Button';
2
3
  export type PaginationOptionValue = string | number;
3
4
  export interface PaginationOption {
4
5
  /**
@@ -6,6 +7,14 @@ export interface PaginationOption {
6
7
  */
7
8
  label: string;
8
9
  value: string | number;
10
+ /**
11
+ * The href of the button. This will make the button render as an anchor tag. If included, the button will override prevent the default link behavior and leave navigation up to the consumer.
12
+ */
13
+ href?: ButtonProps['href'];
14
+ /**
15
+ * The prefetch of the link.
16
+ */
17
+ prefetch?: ButtonProps['prefetch'];
9
18
  }
10
19
  export interface PaginationProps extends Omit<ComponentProps<'div'>, 'onChange'> {
11
20
  /**
@@ -1,84 +1,90 @@
1
- import { jsxs as O, jsx as r } from "react/jsx-runtime";
2
- import f from "../../node_modules/classnames/index.js";
3
- import { getCommonProps as w, px as u } from "../../utils/index.js";
4
- import V from "../Select/Select.js";
5
- import h from "../../assets/chevronRight.svg.js";
6
- import x from "../IconButton/IconButton.js";
7
- import { ButtonVariants as b } from "../Button/types.js";
8
- import { determineOptionValue as i, findOptionFromSelectString as j } from "./utils.js";
9
- import { usePendingState as k } from "../../utils/hooks.js";
10
- const G = ({
11
- className: P,
12
- onChange: $,
13
- variant: S = "inline",
14
- options: n = [],
15
- value: p,
16
- isDisabled: l,
17
- previousLabel: v = "Previous",
18
- nextLabel: C = "Next",
19
- selectLabel: g = "Select",
1
+ import { jsxs as k, jsx as o } from "react/jsx-runtime";
2
+ import { useMemo as B } from "react";
3
+ import v from "../../node_modules/classnames/index.js";
4
+ import { getCommonProps as T, px as u } from "../../utils/index.js";
5
+ import F from "../Select/Select.js";
6
+ import x from "../../assets/chevronRight.svg.js";
7
+ import y from "../IconButton/IconButton.js";
8
+ import { ButtonVariants as P } from "../Button/types.js";
9
+ import { determineOptionValue as i, findOptionFromSelectString as M } from "./utils.js";
10
+ import { usePendingState as R } from "../../utils/hooks.js";
11
+ const L = ({
12
+ className: $,
13
+ onChange: S,
14
+ variant: j = "inline",
15
+ options: a = [],
16
+ value: g,
17
+ isDisabled: m,
18
+ previousLabel: C = "Previous",
19
+ nextLabel: N = "Next",
20
+ selectLabel: b = "Select",
20
21
  ...s
21
22
  }) => {
22
- const N = "pagination", { className: o, ...I } = w(s, "Pagination"), { id: c } = s, { pendingState: _, setPendingState: y } = k(i(p)), m = _ || p, d = (t, e) => {
23
- const a = i(t);
24
- y(a), $(a, e);
25
- };
26
- return /* @__PURE__ */ O(
23
+ const O = "pagination", { className: c, ...I } = T(s, "Pagination"), { id: p } = s, { pendingState: _, setPendingState: w } = R(i(g)), f = _ || g, d = (e, r) => {
24
+ const l = i(e);
25
+ w(l), S(l, r);
26
+ }, [t, n] = B(() => {
27
+ const e = a.findIndex((h) => i(h) === f) - 1, r = a.at(e) || "", l = (a.findIndex((h) => i(h) === f) + 1) % a.length, V = a[l];
28
+ return [r, V];
29
+ }, [a, f]);
30
+ return /* @__PURE__ */ k(
27
31
  "div",
28
32
  {
29
- className: f(`${u}-${N}`, { [`${o}__wrapper`]: o }, P),
33
+ className: v(`${u}-${O}`, { [`${c}__wrapper`]: c }, $),
30
34
  ...I,
31
35
  ...s,
32
36
  children: [
33
- /* @__PURE__ */ r(
34
- x,
37
+ /* @__PURE__ */ o(
38
+ y,
35
39
  {
36
- className: f(`${o}__button`, `${u}-left-arrow`),
37
- onClick: () => {
38
- const t = n.findIndex((a) => i(a) === m) - 1, e = n.at(t) || "";
39
- d(e);
40
+ className: v(`${c}__button`, `${u}-left-arrow`),
41
+ onClick: (e) => {
42
+ typeof t == "object" && t.href && e.preventDefault(), d(t);
40
43
  },
41
- "data-testid": `${c}-previous-button`,
42
- isDisabled: l,
43
- "aria-label": v,
44
- variant: b.primary,
45
- children: /* @__PURE__ */ r(h, {})
44
+ "data-testid": `${p}-previous-button`,
45
+ isDisabled: m,
46
+ "aria-label": C,
47
+ variant: P.primary,
48
+ href: typeof t == "object" && t.href ? t.href : void 0,
49
+ prefetch: typeof t == "object" && t.prefetch ? t.prefetch : void 0,
50
+ children: /* @__PURE__ */ o(x, {})
46
51
  }
47
52
  ),
48
- /* @__PURE__ */ r(
49
- V,
53
+ /* @__PURE__ */ o(
54
+ F,
50
55
  {
51
- className: S === "inline" ? `${u}--inline-pagination` : void 0,
52
- "aria-label": g,
53
- value: m,
54
- onChange: (t) => {
55
- const e = j(n, t == null ? void 0 : t.currentTarget.value);
56
- e && d(e, t);
56
+ className: j === "inline" ? `${u}--inline-pagination` : void 0,
57
+ "aria-label": b,
58
+ value: f,
59
+ onChange: (e) => {
60
+ const r = M(a, e == null ? void 0 : e.currentTarget.value);
61
+ r && d(r, e);
57
62
  },
58
- "data-testid": `${c}-select-button`,
63
+ "data-testid": `${p}-select-button`,
59
64
  hideLabel: !0,
60
- labelText: g,
61
- disabled: l,
65
+ labelText: b,
66
+ disabled: m,
62
67
  showIcon: !1,
63
- children: n.map((t) => {
64
- const e = i(t);
65
- return /* @__PURE__ */ r("option", { value: e, children: typeof t == "string" || typeof t == "number" ? t : t.label }, e);
68
+ children: a.map((e) => {
69
+ const r = i(e);
70
+ return /* @__PURE__ */ o("option", { value: r, children: typeof e == "string" || typeof e == "number" ? e : e.label }, r);
66
71
  })
67
72
  }
68
73
  ),
69
- /* @__PURE__ */ r(
70
- x,
74
+ /* @__PURE__ */ o(
75
+ y,
71
76
  {
72
- className: `${o}__button`,
73
- onClick: () => {
74
- const t = (n.findIndex((a) => i(a) === m) + 1) % n.length, e = n[t];
75
- d(e);
77
+ className: `${c}__button`,
78
+ onClick: (e) => {
79
+ typeof n == "object" && n.href && e.preventDefault(), d(n);
76
80
  },
77
- "data-testid": `${c}-next-button`,
78
- isDisabled: l,
79
- "aria-label": C,
80
- variant: b.primary,
81
- children: /* @__PURE__ */ r(h, {})
81
+ "data-testid": `${p}-next-button`,
82
+ isDisabled: m,
83
+ "aria-label": N,
84
+ variant: P.primary,
85
+ href: typeof n == "object" && n.href ? n.href : void 0,
86
+ prefetch: typeof n == "object" && n.prefetch ? n.prefetch : void 0,
87
+ children: /* @__PURE__ */ o(x, {})
82
88
  }
83
89
  )
84
90
  ]
@@ -86,5 +92,5 @@ const G = ({
86
92
  );
87
93
  };
88
94
  export {
89
- G as default
95
+ L as default
90
96
  };
@@ -37,6 +37,7 @@ export declare const Playground: {
37
37
  };
38
38
  };
39
39
  };
40
+ export declare const PlaygroundWithHrefAndPrefetch: ({ playgroundWidth, onChange, ...args }: StoryProps) => import("react/jsx-runtime").JSX.Element;
40
41
  export declare const StringOptionsPlayground: {
41
42
  ({ playgroundWidth, onChange, ...args }: StoryProps): import("react/jsx-runtime").JSX.Element;
42
43
  args: {
@@ -1,4 +1,4 @@
1
- import { __module as t } from "../../_virtual/index6.js";
1
+ import { __module as t } from "../../_virtual/index5.js";
2
2
  /*!
3
3
  Copyright (c) 2015 Jed Watson.
4
4
  Based on code that is Copyright 2013-2015, Facebook, Inc.
@@ -1,4 +1,4 @@
1
- import { __module as e } from "../../../../_virtual/index5.js";
1
+ import { __module as e } from "../../../../_virtual/index6.js";
2
2
  import { __require as o } from "./cjs/react-is.production.min.js";
3
3
  import { __require as t } from "./cjs/react-is.development.js";
4
4
  var r;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phillips/seldon",
3
- "version": "1.112.1",
3
+ "version": "1.113.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/PhillipsAuctionHouse/seldon"