@viasat/beam-react 2.19.0 → 2.20.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/lib/Card/Card.cjs.js +1 -1
- package/lib/Card/Card.es.js +153 -147
- package/lib/Card/CardContext.d.ts +4 -0
- package/lib/Card/CardGroup.cjs.js +1 -1
- package/lib/Card/CardGroup.d.ts +20 -8
- package/lib/Card/CardGroup.es.js +81 -49
- package/lib/Card/useCardGroup.cjs.js +1 -1
- package/lib/Card/useCardGroup.es.js +16 -16
- package/lib/Card/useCardGroupValue.cjs.js +1 -1
- package/lib/Card/useCardGroupValue.d.ts +2 -1
- package/lib/Card/useCardGroupValue.es.js +33 -21
- package/package.json +6 -6
package/lib/Card/Card.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("react/jsx-runtime"),d=require("react"),T=require("clsx"),ue=require("../../chunks/classNames.DAeKwerT.js");require("../../chunks/constants.hwjHOsvT.js");const be=require("../Box/Box.cjs.js");require("../../chunks/CSSLookup.DESAWWRT.js");require("../../utils/hooks/useId.cjs.js");const fe=require("../../utils/hooks/useInteractiveProps.cjs.js"),t=require("../../chunks/card.module.8KnCe1uR.js"),_e=require("../../chunks/form.context.B26th8Od.js");require("../Form/contexts/label.context.cjs.js");require("../Form/contexts/helperText.context.cjs.js");const ye=require("../Box/utils.cjs.js"),Ce=require("./Card.MediaAbove.cjs.js"),me=require("./Card.Header.cjs.js"),qe=require("./Card.MediaBelow.cjs.js"),ve=require("./Card.Body.cjs.js"),xe=require("./Card.Content.cjs.js"),he=require("./Card.Footer.cjs.js"),pe=require("./CardContext.cjs.js"),Ie=require("./useCardGroup.cjs.js"),$e=require("../StateLayer/StateLayer.cjs.js"),{baseClassNamePrefix:u,classModifierPrefix:c,subElementClassPrefix:b}=ue.getBEMClassNames("card"),ge='button, a, input:not([data-card-input]), select, textarea, [role="button"], [role="link"], [tabindex]:not([tabindex="-1"])',o=({children:P,className:k,density:g="md",borderColor:N,borderRadius:m,backgroundColor:E,shadow:B,type:S,as:L,disabled:O=!1,href:M,target:A,rel:H,onClick:i,selectionMode:j="single",showIndicator:F=!1,selected:V,defaultSelected:K=!1,onSelect:U,name:W,value:X,style:q,...f})=>{const a=pe.useCardGroupContext(),z=!!a,{ctxDisabled:G}=d.useContext(_e.FormContext),J=O||(z?!1:G);process.env.NODE_ENV!=="production"&&a&&S==="clickable"&&console.warn('Card: type="clickable" is ignored when Card is inside a CardGroup; treating as selectable instead.');const v=a?"selectable":S,x=!!v,r=v==="clickable",l=v==="selectable",{selected:h,handleChange:Q,resolvedValue:Y,isSelectionEligible:p,resolvedDisabled:s,resolvedName:Z,resolvedShowIndicator:ee,inputType:w}=Ie.useCardGroup({cardGroup:a,selected:V,defaultSelected:K,value:X,id:f.id,disabled:J,name:W,selectionMode:j,showIndicator:F,onSelect:U}),I=d.useRef(null),_=L??(r&&M?"a":"div"),te=d.useMemo(()=>m?{...q,"--bm-card-radius-outer":ye.BOX_BORDER_RADIUS_TO_CSS_VAR[m]}:q,[m,q]),y=d.useCallback(e=>{if(!e||!(e instanceof Element))return!1;const $=e.closest(ge);if(!$)return!1;const n=e.closest(`.${t.styles[u]}`);return $!==n},[]),D=a==null?void 0:a.readOnly,ae=d.useCallback(e=>{if(s||D)return;if(y(e.target)){if(r&&_==="a"){const n=e.target,R=n==null?void 0:n.closest('a, [role="link"]');(!R||R===e.currentTarget)&&e.preventDefault()}return}if(r&&(i==null||i(e)),l){if(!p)return;const n=e.target;if(n.tagName==="INPUT"&&n.hasAttribute("data-card-input"))return;I.current&&I.current.click()}},[r,l,p,y,_,i,s,D]),re=d.useCallback(e=>{s||e.key!=="Enter"&&e.key!==" "||y(e.target)||(e.preventDefault(),r&&(i==null||i(e)))},[r,y,i,s]),se=T(t.styles[u],!E&&t.styles[`${u}--default-background`],!B&&t.styles[`${u}--default-shadow`],!N&&t.styles[`${u}--default-border`],x&&t.styles[`${c}interactive`],r&&t.styles[`${c}clickable`],l&&t.styles[`${c}selectable`],l&&h&&t.styles[`${c}selected`],s&&t.styles[`${c}disabled`],g&&t.styles[`${c}density-${g}`],k),ie=fe.useInteractiveProps({isInteractive:x,disabled:s,isClickable:r,elementType:_,href:r?M:void 0,target:r?A:void 0,rel:r?H:void 0,onClick:ae,onKeyDown:re}),le=()=>!l||!p?null:C.jsx("input",{ref:I,type:w,className:t.styles[`${b}hidden-input`],checked:h,disabled:s,name:Z,value:Y,onChange:Q,"aria-label":f["aria-label"],"aria-labelledby":f["aria-labelledby"],"aria-invalid":(a==null?void 0:a.isInvalid)||void 0,"aria-errormessage":a==null?void 0:a.validationErrorsId,"data-card-input":""}),ne=()=>{if(!l||!ee)return null;const e=T(t.styles[`${b}selection-indicator`],t.styles[`${b}selection-indicator--${w}`],h&&t.styles[`${b}selection-indicator--checked`],s&&t.styles[`${b}selection-indicator--disabled`]);return C.jsx("span",{className:e,"aria-hidden":"true"})},{"aria-label":oe,"aria-labelledby":de,...ce}=f;return C.jsxs(be.Box,{as:_,className:se,borderColor:N,borderWidth:"md",backgroundColor:E,shadow:B,style:te,...ie,...ce,"aria-label":l?void 0:oe,"aria-labelledby":l?void 0:de,children:[le(),ne(),x&&!s&&C.jsx($e.StateLayer,{}),P]})};o.displayName="Card";o.MediaAbove=Ce.MediaAbove;o.MediaBelow=qe.MediaBelow;o.Header=me.Header;o.Body=ve.Body;o.Content=xe.Content;o.Footer=he.Footer;exports.Card=o;
|
package/lib/Card/Card.es.js
CHANGED
|
@@ -1,197 +1,203 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import
|
|
4
|
-
import { g as
|
|
1
|
+
import { jsxs as me, jsx as x } from "react/jsx-runtime";
|
|
2
|
+
import fe, { useRef as ue, useMemo as be, useCallback as E } from "react";
|
|
3
|
+
import P from "clsx";
|
|
4
|
+
import { g as pe } from "../../chunks/classNames.BTJmrO_L.js";
|
|
5
5
|
import "../../chunks/constants.CKKGf1-i.js";
|
|
6
|
-
import { Box as
|
|
6
|
+
import { Box as he } from "../Box/Box.es.js";
|
|
7
7
|
import "../../chunks/CSSLookup.DOOy1rxJ.js";
|
|
8
8
|
import "../../utils/hooks/useId.es.js";
|
|
9
|
-
import { useInteractiveProps as
|
|
9
|
+
import { useInteractiveProps as ve } from "../../utils/hooks/useInteractiveProps.es.js";
|
|
10
10
|
import { s as t } from "../../chunks/card.module.ByBYpexJ.js";
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
|
|
11
|
+
import { F as ye } from "../../chunks/form.context.BhylRiG2.js";
|
|
12
|
+
import "../Form/contexts/label.context.es.js";
|
|
13
|
+
import "../Form/contexts/helperText.context.es.js";
|
|
14
|
+
import { BOX_BORDER_RADIUS_TO_CSS_VAR as Ie } from "../Box/utils.es.js";
|
|
15
|
+
import { MediaAbove as $e } from "./Card.MediaAbove.es.js";
|
|
16
|
+
import { Header as Ce } from "./Card.Header.es.js";
|
|
17
|
+
import { MediaBelow as ge } from "./Card.MediaBelow.es.js";
|
|
18
|
+
import { Body as xe } from "./Card.Body.es.js";
|
|
19
|
+
import { Content as Ee } from "./Card.Content.es.js";
|
|
20
|
+
import { Footer as Ne } from "./Card.Footer.es.js";
|
|
21
|
+
import { useCardGroupContext as De } from "./CardContext.es.js";
|
|
22
|
+
import { useCardGroup as we } from "./useCardGroup.es.js";
|
|
23
|
+
import { StateLayer as Se } from "../StateLayer/StateLayer.es.js";
|
|
24
|
+
const { baseClassNamePrefix: c, classModifierPrefix: d, subElementClassPrefix: m } = pe("card"), _e = 'button, a, input:not([data-card-input]), select, textarea, [role="button"], [role="link"], [tabindex]:not([tabindex="-1"])', n = ({
|
|
22
25
|
children: T,
|
|
23
26
|
className: A,
|
|
24
|
-
density:
|
|
25
|
-
borderColor:
|
|
26
|
-
borderRadius:
|
|
27
|
-
backgroundColor:
|
|
28
|
-
shadow:
|
|
29
|
-
type:
|
|
27
|
+
density: N = "md",
|
|
28
|
+
borderColor: D,
|
|
29
|
+
borderRadius: p,
|
|
30
|
+
backgroundColor: w,
|
|
31
|
+
shadow: S,
|
|
32
|
+
type: _,
|
|
30
33
|
as: L,
|
|
31
34
|
disabled: k = !1,
|
|
32
|
-
href:
|
|
33
|
-
target:
|
|
34
|
-
rel:
|
|
35
|
-
onClick:
|
|
36
|
-
selectionMode:
|
|
37
|
-
showIndicator:
|
|
38
|
-
selected:
|
|
39
|
-
defaultSelected:
|
|
40
|
-
onSelect:
|
|
41
|
-
name:
|
|
42
|
-
value:
|
|
43
|
-
style:
|
|
44
|
-
...
|
|
35
|
+
href: B,
|
|
36
|
+
target: F,
|
|
37
|
+
rel: H,
|
|
38
|
+
onClick: s,
|
|
39
|
+
selectionMode: V = "single",
|
|
40
|
+
showIndicator: j = !1,
|
|
41
|
+
selected: K,
|
|
42
|
+
defaultSelected: U = !1,
|
|
43
|
+
onSelect: W,
|
|
44
|
+
name: X,
|
|
45
|
+
value: q,
|
|
46
|
+
style: h,
|
|
47
|
+
...f
|
|
45
48
|
}) => {
|
|
46
|
-
const
|
|
47
|
-
process.env.NODE_ENV !== "production" &&
|
|
49
|
+
const a = De(), z = !!a, { ctxDisabled: J } = fe.useContext(ye), Q = k || (z ? !1 : J);
|
|
50
|
+
process.env.NODE_ENV !== "production" && a && _ === "clickable" && console.warn(
|
|
48
51
|
'Card: type="clickable" is ignored when Card is inside a CardGroup; treating as selectable instead.'
|
|
49
52
|
);
|
|
50
|
-
const
|
|
53
|
+
const v = a ? "selectable" : _, y = !!v, r = v === "clickable", o = v === "selectable", {
|
|
51
54
|
selected: I,
|
|
52
|
-
handleChange:
|
|
53
|
-
resolvedValue:
|
|
54
|
-
isSelectionEligible:
|
|
55
|
-
resolvedDisabled:
|
|
56
|
-
resolvedName:
|
|
57
|
-
resolvedShowIndicator:
|
|
58
|
-
inputType:
|
|
59
|
-
} =
|
|
60
|
-
cardGroup:
|
|
61
|
-
selected:
|
|
62
|
-
defaultSelected:
|
|
63
|
-
value:
|
|
64
|
-
id:
|
|
65
|
-
disabled:
|
|
66
|
-
name:
|
|
67
|
-
selectionMode:
|
|
68
|
-
showIndicator:
|
|
69
|
-
onSelect:
|
|
70
|
-
}),
|
|
71
|
-
...
|
|
72
|
-
"--bm-card-radius-outer":
|
|
73
|
-
} :
|
|
55
|
+
handleChange: Y,
|
|
56
|
+
resolvedValue: Z,
|
|
57
|
+
isSelectionEligible: $,
|
|
58
|
+
resolvedDisabled: i,
|
|
59
|
+
resolvedName: G,
|
|
60
|
+
resolvedShowIndicator: ee,
|
|
61
|
+
inputType: M
|
|
62
|
+
} = we({
|
|
63
|
+
cardGroup: a,
|
|
64
|
+
selected: K,
|
|
65
|
+
defaultSelected: U,
|
|
66
|
+
value: q,
|
|
67
|
+
id: f.id,
|
|
68
|
+
disabled: Q,
|
|
69
|
+
name: X,
|
|
70
|
+
selectionMode: V,
|
|
71
|
+
showIndicator: j,
|
|
72
|
+
onSelect: W
|
|
73
|
+
}), C = ue(null), u = L ?? (r && B ? "a" : "div"), te = be(() => p ? {
|
|
74
|
+
...h,
|
|
75
|
+
"--bm-card-radius-outer": Ie[p]
|
|
76
|
+
} : h, [p, h]), b = E(
|
|
74
77
|
(e) => {
|
|
75
78
|
if (!e || !(e instanceof Element)) return !1;
|
|
76
|
-
const
|
|
77
|
-
if (!
|
|
78
|
-
const
|
|
79
|
-
return
|
|
79
|
+
const g = e.closest(_e);
|
|
80
|
+
if (!g) return !1;
|
|
81
|
+
const l = e.closest(`.${t[c]}`);
|
|
82
|
+
return g !== l;
|
|
80
83
|
},
|
|
81
84
|
[]
|
|
82
|
-
),
|
|
85
|
+
), R = a == null ? void 0 : a.readOnly, ae = E(
|
|
83
86
|
(e) => {
|
|
84
|
-
if (
|
|
85
|
-
if (
|
|
86
|
-
if (r &&
|
|
87
|
-
const
|
|
88
|
-
(!
|
|
87
|
+
if (i || R) return;
|
|
88
|
+
if (b(e.target)) {
|
|
89
|
+
if (r && u === "a") {
|
|
90
|
+
const l = e.target, O = l == null ? void 0 : l.closest('a, [role="link"]');
|
|
91
|
+
(!O || O === e.currentTarget) && e.preventDefault();
|
|
89
92
|
}
|
|
90
93
|
return;
|
|
91
94
|
}
|
|
92
|
-
if (r && (
|
|
93
|
-
if (
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
95
|
+
if (r && (s == null || s(e)), o) {
|
|
96
|
+
if (!$) return;
|
|
97
|
+
const l = e.target;
|
|
98
|
+
if (l.tagName === "INPUT" && l.hasAttribute("data-card-input"))
|
|
96
99
|
return;
|
|
97
|
-
|
|
100
|
+
C.current && C.current.click();
|
|
98
101
|
}
|
|
99
102
|
},
|
|
100
103
|
[
|
|
101
104
|
r,
|
|
102
105
|
o,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
$,
|
|
107
|
+
b,
|
|
108
|
+
u,
|
|
109
|
+
s,
|
|
106
110
|
i,
|
|
107
|
-
|
|
111
|
+
R
|
|
108
112
|
]
|
|
109
|
-
),
|
|
113
|
+
), re = E(
|
|
110
114
|
(e) => {
|
|
111
|
-
|
|
115
|
+
i || e.key !== "Enter" && e.key !== " " || b(e.target) || (e.preventDefault(), r && (s == null || s(e)));
|
|
112
116
|
},
|
|
113
|
-
[r,
|
|
114
|
-
),
|
|
115
|
-
t[
|
|
116
|
-
!
|
|
117
|
-
!
|
|
118
|
-
!
|
|
119
|
-
|
|
120
|
-
r && t[`${
|
|
121
|
-
o && t[`${
|
|
122
|
-
o && I && t[`${
|
|
123
|
-
|
|
124
|
-
|
|
117
|
+
[r, b, s, i]
|
|
118
|
+
), ie = P(
|
|
119
|
+
t[c],
|
|
120
|
+
!w && t[`${c}--default-background`],
|
|
121
|
+
!S && t[`${c}--default-shadow`],
|
|
122
|
+
!D && t[`${c}--default-border`],
|
|
123
|
+
y && t[`${d}interactive`],
|
|
124
|
+
r && t[`${d}clickable`],
|
|
125
|
+
o && t[`${d}selectable`],
|
|
126
|
+
o && I && t[`${d}selected`],
|
|
127
|
+
i && t[`${d}disabled`],
|
|
128
|
+
N && t[`${d}density-${N}`],
|
|
125
129
|
A
|
|
126
|
-
),
|
|
127
|
-
isInteractive:
|
|
128
|
-
disabled:
|
|
130
|
+
), se = ve({
|
|
131
|
+
isInteractive: y,
|
|
132
|
+
disabled: i,
|
|
129
133
|
isClickable: r,
|
|
130
|
-
elementType:
|
|
131
|
-
href: r ?
|
|
132
|
-
target: r ?
|
|
133
|
-
rel: r ?
|
|
134
|
-
onClick:
|
|
135
|
-
onKeyDown:
|
|
136
|
-
}),
|
|
134
|
+
elementType: u,
|
|
135
|
+
href: r ? B : void 0,
|
|
136
|
+
target: r ? F : void 0,
|
|
137
|
+
rel: r ? H : void 0,
|
|
138
|
+
onClick: ae,
|
|
139
|
+
onKeyDown: re
|
|
140
|
+
}), oe = () => !o || !$ ? null : /* @__PURE__ */ x(
|
|
137
141
|
"input",
|
|
138
142
|
{
|
|
139
|
-
ref:
|
|
140
|
-
type:
|
|
141
|
-
className: t[`${
|
|
143
|
+
ref: C,
|
|
144
|
+
type: M,
|
|
145
|
+
className: t[`${m}hidden-input`],
|
|
142
146
|
checked: I,
|
|
143
|
-
disabled:
|
|
144
|
-
name:
|
|
145
|
-
value:
|
|
146
|
-
onChange:
|
|
147
|
-
"aria-label":
|
|
148
|
-
"aria-labelledby":
|
|
147
|
+
disabled: i,
|
|
148
|
+
name: G,
|
|
149
|
+
value: Z,
|
|
150
|
+
onChange: Y,
|
|
151
|
+
"aria-label": f["aria-label"],
|
|
152
|
+
"aria-labelledby": f["aria-labelledby"],
|
|
153
|
+
"aria-invalid": (a == null ? void 0 : a.isInvalid) || void 0,
|
|
154
|
+
"aria-errormessage": a == null ? void 0 : a.validationErrorsId,
|
|
149
155
|
"data-card-input": ""
|
|
150
156
|
}
|
|
151
|
-
),
|
|
152
|
-
if (!o || !
|
|
153
|
-
const e =
|
|
154
|
-
t[`${
|
|
155
|
-
t[`${
|
|
156
|
-
I && t[`${
|
|
157
|
-
|
|
157
|
+
), le = () => {
|
|
158
|
+
if (!o || !ee) return null;
|
|
159
|
+
const e = P(
|
|
160
|
+
t[`${m}selection-indicator`],
|
|
161
|
+
t[`${m}selection-indicator--${M}`],
|
|
162
|
+
I && t[`${m}selection-indicator--checked`],
|
|
163
|
+
i && t[`${m}selection-indicator--disabled`]
|
|
158
164
|
);
|
|
159
|
-
return /* @__PURE__ */
|
|
165
|
+
return /* @__PURE__ */ x("span", { className: e, "aria-hidden": "true" });
|
|
160
166
|
}, {
|
|
161
|
-
"aria-label":
|
|
162
|
-
"aria-labelledby":
|
|
163
|
-
...
|
|
164
|
-
} =
|
|
165
|
-
return /* @__PURE__ */
|
|
166
|
-
|
|
167
|
+
"aria-label": ne,
|
|
168
|
+
"aria-labelledby": de,
|
|
169
|
+
...ce
|
|
170
|
+
} = f;
|
|
171
|
+
return /* @__PURE__ */ me(
|
|
172
|
+
he,
|
|
167
173
|
{
|
|
168
|
-
as:
|
|
169
|
-
className:
|
|
170
|
-
borderColor:
|
|
174
|
+
as: u,
|
|
175
|
+
className: ie,
|
|
176
|
+
borderColor: D,
|
|
171
177
|
borderWidth: "md",
|
|
172
|
-
backgroundColor:
|
|
173
|
-
shadow:
|
|
174
|
-
style:
|
|
175
|
-
...te,
|
|
178
|
+
backgroundColor: w,
|
|
179
|
+
shadow: S,
|
|
180
|
+
style: te,
|
|
176
181
|
...se,
|
|
177
|
-
|
|
178
|
-
"aria-
|
|
182
|
+
...ce,
|
|
183
|
+
"aria-label": o ? void 0 : ne,
|
|
184
|
+
"aria-labelledby": o ? void 0 : de,
|
|
179
185
|
children: [
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
186
|
+
oe(),
|
|
187
|
+
le(),
|
|
188
|
+
y && !i && /* @__PURE__ */ x(Se, {}),
|
|
183
189
|
T
|
|
184
190
|
]
|
|
185
191
|
}
|
|
186
192
|
);
|
|
187
193
|
};
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
194
|
+
n.displayName = "Card";
|
|
195
|
+
n.MediaAbove = $e;
|
|
196
|
+
n.MediaBelow = ge;
|
|
197
|
+
n.Header = Ce;
|
|
198
|
+
n.Body = xe;
|
|
199
|
+
n.Content = Ee;
|
|
200
|
+
n.Footer = Ne;
|
|
195
201
|
export {
|
|
196
|
-
|
|
202
|
+
n as Card
|
|
197
203
|
};
|
|
@@ -5,8 +5,12 @@ export interface CardGroupContextValue {
|
|
|
5
5
|
showIndicator?: boolean;
|
|
6
6
|
name?: string;
|
|
7
7
|
disabled?: boolean;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
readOnly?: boolean;
|
|
8
10
|
value?: string | string[];
|
|
9
11
|
onItemSelect?: (value: string, event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
12
|
+
validationErrorsId?: string;
|
|
13
|
+
isInvalid?: boolean;
|
|
10
14
|
}
|
|
11
15
|
export declare const CardGroupProvider: ({ children, value, }: {
|
|
12
16
|
children: React.ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),u=require("react"),E=require("../../utils/functions.cjs.js"),k=require("clsx"),F=require("../../chunks/classNames.DAeKwerT.js");require("../../chunks/constants.hwjHOsvT.js");const T=require("../../chunks/card.module.8KnCe1uR.js");require("../../chunks/CSSLookup.DESAWWRT.js");const A=require("../../utils/hooks/useId.cjs.js"),B=require("../Form/hooks/useAccessibleId.hook.cjs.js"),H=require("../../chunks/form.context.B26th8Od.js");require("../Form/contexts/label.context.cjs.js");require("../Form/contexts/helperText.context.cjs.js");const L=require("./CardContext.cjs.js"),$=require("./useCardGroupValue.cjs.js"),{classModifierPrefix:z}=F.getBEMClassNames("card"),q=u.forwardRef((v,_)=>{const{children:f,className:p,disabled:y=!1,required:C=!1,readOnly:g=!1,validationRules:h=[],selectionMode:e="single",showIndicator:n=!1,name:I,value:x,defaultValue:N,onChange:R,"aria-label":G,"aria-labelledby":P,...M}=v,O=A.useId(),{id:r}=B.useAccessibleId(),o=I??O,{showErrors:S,isInvalid:i,errorShown:l,disabled:a,readOnly:s,required:d}=H.useFormField({name:o,validationRules:h,disabledProp:y,readOnlyProp:g,requiredProp:C}),t=u.useRef(null),{currentValue:c,handleItemSelect:b}=$.useCardGroupValue({value:x,defaultValue:N,selectionMode:e,onChange:R,rootRef:t}),V=k(a&&T.styles[`${z}disabled`],p),j=e==="single"?"radiogroup":"group",w=u.useMemo(()=>({selectionMode:e,showIndicator:n,name:o,disabled:a,required:d,readOnly:s,value:c,onItemSelect:b,validationErrorsId:l?r:void 0,isInvalid:i}),[e,n,o,a,d,s,c,b,l,r,i]);return m.jsxs("div",{ref:E.mergeRefs(t,_),role:j,"aria-disabled":a||s||void 0,"aria-readonly":s||void 0,"aria-required":d||void 0,"aria-invalid":i||void 0,"aria-errormessage":l?r:void 0,"aria-label":G,"aria-labelledby":P,className:V,...M,children:[m.jsx(L.CardGroupProvider,{value:w,children:f}),S(r)]})});q.displayName="CardGroup";exports.CardGroup=q;
|
package/lib/Card/CardGroup.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { default as React } from 'react';
|
|
1
|
+
import { default as React, ComponentPropsWithoutRef } from 'react';
|
|
2
2
|
import { CardGroupSelectionMode } from '@viasat/beam-shared/components/card';
|
|
3
|
-
|
|
3
|
+
import { FormValidator } from '@viasat/beam-shared/components/form';
|
|
4
|
+
export interface CardGroupProps extends Omit<ComponentPropsWithoutRef<'div'>, 'onChange'> {
|
|
4
5
|
/**
|
|
5
6
|
* The Cards that belong to this CardGroup
|
|
6
7
|
*/
|
|
7
|
-
children?: React.ReactNode;
|
|
8
|
+
'children'?: React.ReactNode;
|
|
8
9
|
/**
|
|
9
10
|
* Accessible group label
|
|
10
11
|
*/
|
|
@@ -48,8 +49,19 @@ export type CardGroupProps = Omit<React.ComponentPropsWithoutRef<'div'>, 'onChan
|
|
|
48
49
|
* Callback invoked when the group selection changes
|
|
49
50
|
*/
|
|
50
51
|
'onChange'?: (value: string | string[] | undefined, event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Specify if the group is a required field
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
'required'?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Specify if the group displays in a read-only state
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
'readOnly'?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Specify form validation rules for the group
|
|
64
|
+
*/
|
|
65
|
+
'validationRules'?: FormValidator[];
|
|
66
|
+
}
|
|
67
|
+
export declare const CardGroup: React.ForwardRefExoticComponent<CardGroupProps & React.RefAttributes<HTMLDivElement>>;
|
package/lib/Card/CardGroup.es.js
CHANGED
|
@@ -1,67 +1,99 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useMemo as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { jsxs as O, jsx as V } from "react/jsx-runtime";
|
|
2
|
+
import S, { forwardRef as j, useMemo as B } from "react";
|
|
3
|
+
import { mergeRefs as F } from "../../utils/functions.es.js";
|
|
4
|
+
import L from "clsx";
|
|
5
|
+
import { g as A } from "../../chunks/classNames.BTJmrO_L.js";
|
|
5
6
|
import "../../chunks/constants.CKKGf1-i.js";
|
|
6
|
-
import { s as
|
|
7
|
+
import { s as $ } from "../../chunks/card.module.ByBYpexJ.js";
|
|
7
8
|
import "../../chunks/CSSLookup.DOOy1rxJ.js";
|
|
8
|
-
import { useId as
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
9
|
+
import { useId as k } from "../../utils/hooks/useId.es.js";
|
|
10
|
+
import { useAccessibleId as z } from "../Form/hooks/useAccessibleId.hook.es.js";
|
|
11
|
+
import { b as D } from "../../chunks/form.context.BhylRiG2.js";
|
|
12
|
+
import "../Form/contexts/label.context.es.js";
|
|
13
|
+
import "../Form/contexts/helperText.context.es.js";
|
|
14
|
+
import { CardGroupProvider as H } from "./CardContext.es.js";
|
|
15
|
+
import { useCardGroupValue as J } from "./useCardGroupValue.es.js";
|
|
16
|
+
const { classModifierPrefix: K } = A("card"), Q = j((c, p) => {
|
|
12
17
|
const {
|
|
13
|
-
children:
|
|
14
|
-
className:
|
|
15
|
-
disabled:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
children: f,
|
|
19
|
+
className: v,
|
|
20
|
+
disabled: b = !1,
|
|
21
|
+
required: y = !1,
|
|
22
|
+
readOnly: g = !1,
|
|
23
|
+
validationRules: I = [],
|
|
24
|
+
selectionMode: e = "single",
|
|
25
|
+
showIndicator: t = !1,
|
|
26
|
+
name: h,
|
|
27
|
+
value: N,
|
|
28
|
+
defaultValue: x,
|
|
29
|
+
onChange: C,
|
|
30
|
+
"aria-label": R,
|
|
31
|
+
"aria-labelledby": _,
|
|
32
|
+
...q
|
|
33
|
+
} = c, P = k(), { id: r } = z(), i = h ?? P, { showErrors: w, isInvalid: s, errorShown: l, disabled: a, readOnly: o, required: d } = D({
|
|
34
|
+
name: i,
|
|
35
|
+
validationRules: I,
|
|
36
|
+
disabledProp: b,
|
|
37
|
+
readOnlyProp: g,
|
|
38
|
+
requiredProp: y
|
|
39
|
+
}), m = S.useRef(null), { currentValue: n, handleItemSelect: u } = J({
|
|
40
|
+
value: N,
|
|
41
|
+
defaultValue: x,
|
|
42
|
+
selectionMode: e,
|
|
43
|
+
onChange: C,
|
|
44
|
+
rootRef: m
|
|
45
|
+
}), E = L(
|
|
46
|
+
a && $[`${K}disabled`],
|
|
47
|
+
v
|
|
48
|
+
), G = e === "single" ? "radiogroup" : "group", M = B(
|
|
34
49
|
() => ({
|
|
35
|
-
selectionMode:
|
|
36
|
-
showIndicator:
|
|
37
|
-
name:
|
|
38
|
-
disabled:
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
selectionMode: e,
|
|
51
|
+
showIndicator: t,
|
|
52
|
+
name: i,
|
|
53
|
+
disabled: a,
|
|
54
|
+
required: d,
|
|
55
|
+
readOnly: o,
|
|
56
|
+
value: n,
|
|
57
|
+
onItemSelect: u,
|
|
58
|
+
validationErrorsId: l ? r : void 0,
|
|
59
|
+
isInvalid: s
|
|
41
60
|
}),
|
|
42
61
|
[
|
|
62
|
+
e,
|
|
63
|
+
t,
|
|
64
|
+
i,
|
|
43
65
|
a,
|
|
44
|
-
|
|
66
|
+
d,
|
|
45
67
|
o,
|
|
46
|
-
|
|
68
|
+
n,
|
|
69
|
+
u,
|
|
47
70
|
l,
|
|
71
|
+
r,
|
|
48
72
|
s
|
|
49
73
|
]
|
|
50
74
|
);
|
|
51
|
-
return /* @__PURE__ */
|
|
75
|
+
return /* @__PURE__ */ O(
|
|
52
76
|
"div",
|
|
53
77
|
{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"aria-
|
|
57
|
-
"aria-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
78
|
+
ref: F(m, p),
|
|
79
|
+
role: G,
|
|
80
|
+
"aria-disabled": a || o || void 0,
|
|
81
|
+
"aria-readonly": o || void 0,
|
|
82
|
+
"aria-required": d || void 0,
|
|
83
|
+
"aria-invalid": s || void 0,
|
|
84
|
+
"aria-errormessage": l ? r : void 0,
|
|
85
|
+
"aria-label": R,
|
|
86
|
+
"aria-labelledby": _,
|
|
87
|
+
className: E,
|
|
88
|
+
...q,
|
|
89
|
+
children: [
|
|
90
|
+
/* @__PURE__ */ V(H, { value: M, children: f }),
|
|
91
|
+
w(r)
|
|
92
|
+
]
|
|
61
93
|
}
|
|
62
94
|
);
|
|
63
|
-
};
|
|
64
|
-
|
|
95
|
+
});
|
|
96
|
+
Q.displayName = "CardGroup";
|
|
65
97
|
export {
|
|
66
|
-
|
|
98
|
+
Q as CardGroup
|
|
67
99
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),D=require("./card.utils.cjs.js");function a({cardGroup:e,selected:C,defaultSelected:S,value:b,id:m,disabled:y,name:I,selectionMode:M,showIndicator:h,onSelect:n}){const t=!!e,s=b??m,o=!t||!!s;i.useEffect(()=>{process.env.NODE_ENV!=="production"&&t&&!s&&console.warn("Card: A Card inside a CardGroup is missing a `value` or `id` prop. It will not participate in group selection.")},[]);const f=y||(e==null?void 0:e.disabled)||!1,w=(e==null?void 0:e.name)??I,E=(e==null?void 0:e.showIndicator)??h,_=(e==null?void 0:e.selectionMode)??M??"single",A=D.getInputType(_),[N,O]=i.useState(()=>t?!1:S),T=C!==void 0?C:N,l=e==null?void 0:e.value,v=(e==null?void 0:e.selectionMode)??"single",V=i.useMemo(()=>!t||!s?null:v==="single"?l===s:Array.isArray(l)?l.includes(s):!1,[l,v,t,s]),k=t?V??!1:T,q=i.useCallback(g=>{f||e!=null&&e.readOnly||!o||(e!=null&&e.onItemSelect&&s?e.onItemSelect(s,g):O(g.target.checked),n==null||n(g))},[f,o,e,s,n]);return{selected:k,handleChange:q,resolvedValue:s,isSelectionEligible:o,resolvedDisabled:f,resolvedName:w,resolvedShowIndicator:E,inputType:A}}exports.useCardGroup=a;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect as
|
|
1
|
+
import { useEffect as x, useState as _, useMemo as j, useCallback as q } from "react";
|
|
2
2
|
import { getInputType as z } from "./card.utils.es.js";
|
|
3
3
|
function J({
|
|
4
4
|
cardGroup: e,
|
|
@@ -8,32 +8,32 @@ function J({
|
|
|
8
8
|
id: I,
|
|
9
9
|
disabled: S,
|
|
10
10
|
name: h,
|
|
11
|
-
selectionMode:
|
|
12
|
-
showIndicator:
|
|
11
|
+
selectionMode: y,
|
|
12
|
+
showIndicator: M,
|
|
13
13
|
onSelect: n
|
|
14
14
|
}) {
|
|
15
|
-
const t = !!e, s = v ?? I,
|
|
16
|
-
|
|
15
|
+
const t = !!e, s = v ?? I, i = !t || !!s;
|
|
16
|
+
x(() => {
|
|
17
17
|
process.env.NODE_ENV !== "production" && t && !s && console.warn(
|
|
18
18
|
"Card: A Card inside a CardGroup is missing a `value` or `id` prop. It will not participate in group selection."
|
|
19
19
|
);
|
|
20
20
|
}, []);
|
|
21
|
-
const
|
|
21
|
+
const f = S || (e == null ? void 0 : e.disabled) || !1, b = (e == null ? void 0 : e.name) ?? h, w = (e == null ? void 0 : e.showIndicator) ?? M, E = (e == null ? void 0 : e.selectionMode) ?? y ?? "single", A = z(E), [N, V] = _(
|
|
22
22
|
() => t ? !1 : C
|
|
23
|
-
), k = g !== void 0 ? g : N,
|
|
24
|
-
(
|
|
25
|
-
|
|
23
|
+
), k = g !== void 0 ? g : N, l = e == null ? void 0 : e.value, m = (e == null ? void 0 : e.selectionMode) ?? "single", D = j(() => !t || !s ? null : m === "single" ? l === s : Array.isArray(l) ? l.includes(s) : !1, [l, m, t, s]), O = t ? D ?? !1 : k, T = q(
|
|
24
|
+
(o) => {
|
|
25
|
+
f || e != null && e.readOnly || !i || (e != null && e.onItemSelect && s ? e.onItemSelect(s, o) : V(o.target.checked), n == null || n(o));
|
|
26
26
|
},
|
|
27
|
-
[
|
|
27
|
+
[f, i, e, s, n]
|
|
28
28
|
);
|
|
29
29
|
return {
|
|
30
|
-
selected:
|
|
31
|
-
handleChange:
|
|
30
|
+
selected: O,
|
|
31
|
+
handleChange: T,
|
|
32
32
|
resolvedValue: s,
|
|
33
|
-
isSelectionEligible:
|
|
34
|
-
resolvedDisabled:
|
|
35
|
-
resolvedName:
|
|
36
|
-
resolvedShowIndicator:
|
|
33
|
+
isSelectionEligible: i,
|
|
34
|
+
resolvedDisabled: f,
|
|
35
|
+
resolvedName: b,
|
|
36
|
+
resolvedShowIndicator: w,
|
|
37
37
|
inputType: A
|
|
38
38
|
};
|
|
39
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),l=require("./card.utils.cjs.js");function A({value:f,defaultValue:m,selectionMode:u,onChange:e,rootRef:c}){const t=f!==void 0,y=i.useRef(u==="single"?l.normalizeToSingle(m):l.normalizeToArray(m)),[T,a]=i.useState(()=>y.current);i.useEffect(()=>{var s;if(t)return;const r=(s=c==null?void 0:c.current)==null?void 0:s.closest("form");if(!r)return;const n=()=>a(y.current);return r.addEventListener("reset",n),()=>r.removeEventListener("reset",n)},[t,c]);const o=t?f:T,d=i.useMemo(()=>u==="single"?l.normalizeToSingle(o):l.normalizeToArray(o),[o,u]),z=i.useCallback((r,n)=>{if(u==="single"){t||a(r),e==null||e(r,n);return}const s=l.normalizeToArray(d),S=s.includes(r)?s.filter(b=>b!==r):[...s,r];t||a(S),e==null||e(S,n)},[u,d,t,e]);return{currentValue:d,handleItemSelect:z}}exports.useCardGroupValue=A;
|
|
@@ -5,10 +5,11 @@ interface UseCardGroupValueParams {
|
|
|
5
5
|
defaultValue: string | string[] | undefined;
|
|
6
6
|
selectionMode: CardGroupSelectionMode;
|
|
7
7
|
onChange?: (value: string | string[] | undefined, event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
8
|
+
rootRef?: React.RefObject<HTMLDivElement>;
|
|
8
9
|
}
|
|
9
10
|
interface UseCardGroupValueReturn {
|
|
10
11
|
currentValue: string | string[] | undefined;
|
|
11
12
|
handleItemSelect: (itemValue: string, event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
12
13
|
}
|
|
13
|
-
export declare function useCardGroupValue({ value, defaultValue, selectionMode, onChange, }: UseCardGroupValueParams): UseCardGroupValueReturn;
|
|
14
|
+
export declare function useCardGroupValue({ value, defaultValue, selectionMode, onChange, rootRef, }: UseCardGroupValueParams): UseCardGroupValueReturn;
|
|
14
15
|
export {};
|
|
@@ -1,29 +1,41 @@
|
|
|
1
|
-
import { useState as I, useMemo as
|
|
2
|
-
import { normalizeToSingle as
|
|
3
|
-
function
|
|
4
|
-
value:
|
|
5
|
-
defaultValue:
|
|
6
|
-
selectionMode:
|
|
7
|
-
onChange:
|
|
1
|
+
import { useRef as z, useState as A, useEffect as I, useMemo as L, useCallback as T } from "react";
|
|
2
|
+
import { normalizeToSingle as S, normalizeToArray as m } from "./card.utils.es.js";
|
|
3
|
+
function k({
|
|
4
|
+
value: a,
|
|
5
|
+
defaultValue: p,
|
|
6
|
+
selectionMode: u,
|
|
7
|
+
onChange: t,
|
|
8
|
+
rootRef: n
|
|
8
9
|
}) {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
),
|
|
12
|
-
() =>
|
|
13
|
-
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
const s = a !== void 0, d = z(
|
|
11
|
+
u === "single" ? S(p) : m(p)
|
|
12
|
+
), [v, i] = A(
|
|
13
|
+
() => d.current
|
|
14
|
+
);
|
|
15
|
+
I(() => {
|
|
16
|
+
var e;
|
|
17
|
+
if (s) return;
|
|
18
|
+
const r = (e = n == null ? void 0 : n.current) == null ? void 0 : e.closest("form");
|
|
19
|
+
if (!r) return;
|
|
20
|
+
const c = () => i(d.current);
|
|
21
|
+
return r.addEventListener("reset", c), () => r.removeEventListener("reset", c);
|
|
22
|
+
}, [s, n]);
|
|
23
|
+
const l = s ? a : v, f = L(
|
|
24
|
+
() => u === "single" ? S(l) : m(l),
|
|
25
|
+
[l, u]
|
|
26
|
+
), x = T(
|
|
27
|
+
(r, c) => {
|
|
28
|
+
if (u === "single") {
|
|
29
|
+
s || i(r), t == null || t(r, c);
|
|
18
30
|
return;
|
|
19
31
|
}
|
|
20
|
-
const
|
|
21
|
-
|
|
32
|
+
const e = m(f), E = e.includes(r) ? e.filter((y) => y !== r) : [...e, r];
|
|
33
|
+
s || i(E), t == null || t(E, c);
|
|
22
34
|
},
|
|
23
|
-
[
|
|
35
|
+
[u, f, s, t]
|
|
24
36
|
);
|
|
25
|
-
return { currentValue:
|
|
37
|
+
return { currentValue: f, handleItemSelect: x };
|
|
26
38
|
}
|
|
27
39
|
export {
|
|
28
|
-
|
|
40
|
+
k as useCardGroupValue
|
|
29
41
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viasat/beam-react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.0",
|
|
4
4
|
"description": "React component library for the Beam design system",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Viasat",
|
|
@@ -59,11 +59,11 @@
|
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@viasat/beam-fonts": "2.
|
|
63
|
-
"@viasat/beam-shared": "2.
|
|
64
|
-
"@viasat/beam-styles": "2.
|
|
65
|
-
"@viasat/beam-tokens": "2.
|
|
66
|
-
"@viasat/beam-icons": "2.
|
|
62
|
+
"@viasat/beam-fonts": "2.20.0",
|
|
63
|
+
"@viasat/beam-shared": "2.20.0",
|
|
64
|
+
"@viasat/beam-styles": "2.20.0",
|
|
65
|
+
"@viasat/beam-tokens": "2.20.0",
|
|
66
|
+
"@viasat/beam-icons": "2.20.0",
|
|
67
67
|
"clsx": "^1.2.1",
|
|
68
68
|
"@floating-ui/react": "^0.26.18",
|
|
69
69
|
"@stepperize/react": "^5.1.5",
|