@fluentui/react-card 9.0.0-beta.34 → 9.0.0-beta.36
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/CHANGELOG.json +73 -1
- package/CHANGELOG.md +27 -2
- package/dist/index.d.ts +43 -22
- package/lib/components/Card/Card.js +3 -1
- package/lib/components/Card/Card.js.map +1 -1
- package/lib/components/Card/Card.types.js.map +1 -1
- package/lib/components/Card/CardContext.js +37 -0
- package/lib/components/Card/CardContext.js.map +1 -0
- package/lib/components/Card/index.js +1 -0
- package/lib/components/Card/index.js.map +1 -1
- package/lib/components/Card/renderCard.js +7 -3
- package/lib/components/Card/renderCard.js.map +1 -1
- package/lib/components/Card/useCard.js +52 -31
- package/lib/components/Card/useCard.js.map +1 -1
- package/lib/components/Card/useCardContextValue.js +8 -0
- package/lib/components/Card/useCardContextValue.js.map +1 -0
- package/lib/components/Card/useCardSelectable.js +59 -36
- package/lib/components/Card/useCardSelectable.js.map +1 -1
- package/lib/components/Card/useCardStyles.js +73 -56
- package/lib/components/Card/useCardStyles.js.map +1 -1
- package/lib/components/CardHeader/CardHeader.types.js.map +1 -1
- package/lib/components/CardHeader/useCardHeader.js +27 -4
- package/lib/components/CardHeader/useCardHeader.js.map +1 -1
- package/lib/components/CardPreview/useCardPreview.js +36 -2
- package/lib/components/CardPreview/useCardPreview.js.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib-commonjs/components/Card/Card.js +4 -1
- package/lib-commonjs/components/Card/Card.js.map +1 -1
- package/lib-commonjs/components/Card/CardContext.js +47 -0
- package/lib-commonjs/components/Card/CardContext.js.map +1 -0
- package/lib-commonjs/components/Card/index.js +2 -0
- package/lib-commonjs/components/Card/index.js.map +1 -1
- package/lib-commonjs/components/Card/renderCard.js +8 -3
- package/lib-commonjs/components/Card/renderCard.js.map +1 -1
- package/lib-commonjs/components/Card/useCard.js +51 -29
- package/lib-commonjs/components/Card/useCard.js.map +1 -1
- package/lib-commonjs/components/Card/useCardContextValue.js +17 -0
- package/lib-commonjs/components/Card/useCardContextValue.js.map +1 -0
- package/lib-commonjs/components/Card/useCardSelectable.js +58 -35
- package/lib-commonjs/components/Card/useCardSelectable.js.map +1 -1
- package/lib-commonjs/components/Card/useCardStyles.js +73 -56
- package/lib-commonjs/components/Card/useCardStyles.js.map +1 -1
- package/lib-commonjs/components/CardHeader/useCardHeader.js +29 -3
- package/lib-commonjs/components/CardHeader/useCardHeader.js.map +1 -1
- package/lib-commonjs/components/CardPreview/useCardPreview.js +38 -1
- package/lib-commonjs/components/CardPreview/useCardPreview.js.map +1 -1
- package/lib-commonjs/index.js +16 -1
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +5 -5
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-card/src/components/CardPreview/useCardPreview.ts"],"names":[],"mappings":"AACA,SAAS,qBAAT,EAAgC,gBAAhC,
|
1
|
+
{"version":3,"sources":["packages/react-components/react-card/src/components/CardPreview/useCardPreview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,qBAAT,EAAgC,gBAAhC,EAAkD,aAAlD,QAAuE,2BAAvE;AAEA,SAAS,uBAAT,QAAwC,qBAAxC;AACA,SAAS,qBAAT,QAAsC,wBAAtC;AAEA;;;;;;;;AAQG;;AACH,OAAO,MAAM,uBAAuB,GAAG,CAAC,KAAD,EAA0B,GAA1B,KAA2E;EAChH,MAAM;IAAE;EAAF,IAAW,KAAjB;EAEA,MAAM;IACJ,mBAAmB,EAAE;MAAE,cAAF;MAAkB,WAAlB;MAA+B,iBAA/B;MAAkD;IAAlD;EADjB,IAEF,uBAAuB,EAF3B;EAGA,MAAM,UAAU,GAAG,aAAa,CAAC,GAAD,EAAM,KAAK,CAAC,MAAN,CAA6B,IAA7B,CAAN,CAAhC;EAEA,KAAK,CAAC,SAAN,CAAgB,MAAK;IACnB,IAAI,cAAc,IAAI,WAAtB,EAAmC;MACjC;IACD;;IAED,IAAI,UAAU,CAAC,OAAX,IAAsB,UAAU,CAAC,OAAX,CAAmB,UAA7C,EAAyD;MACvD,MAAM,GAAG,GAAG,UAAU,CAAC,OAAX,CAAmB,UAAnB,CAA8B,aAA9B,CAA8D,IAAI,qBAAqB,CAAC,IAAI,QAA5F,CAAZ;;MAEA,IAAI,GAAJ,EAAS;QACP,MAAM,SAAS,GAAG,GAAG,CAAC,YAAJ,CAAiB,YAAjB,CAAlB;QACA,MAAM,eAAe,GAAG,GAAG,CAAC,YAAJ,CAAiB,kBAAjB,CAAxB;;QAEA,IAAI,eAAJ,EAAqB;UACnB,cAAc,CAAC,eAAD,CAAd;QACD,CAFD,MAEO,IAAI,GAAG,CAAC,GAAR,EAAa;UAClB,iBAAiB,CAAC,GAAG,CAAC,GAAL,CAAjB;QACD,CAFM,MAEA,IAAI,SAAJ,EAAe;UACpB,iBAAiB,CAAC,SAAD,CAAjB;QACD;MACF;IACF;EACF,CArBD,EAqBG,CAAC,iBAAD,EAAoB,cAApB,EAAoC,UAApC,EAAgD,WAAhD,EAA6D,cAA7D,CArBH;EAuBA,OAAO;IACL,UAAU,EAAE;MACV,IAAI,EAAE,KADI;MAEV,IAAI,EAAE;IAFI,CADP;IAML,IAAI,EAAE,qBAAqB,CAAC,KAAD,EAAQ;MACjC,GAAG,EAAE,UAD4B;MAEjC,GAAG;IAF8B,CAAR,CANtB;IAUL,IAAI,EAAE,gBAAgB,CAAC,IAAD;EAVjB,CAAP;AAYD,CA3CM","sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, resolveShorthand, useMergedRefs } from '@fluentui/react-utilities';\nimport type { CardPreviewProps, CardPreviewState } from './CardPreview.types';\nimport { useCardContext_unstable } from '../Card/CardContext';\nimport { cardPreviewClassNames } from './useCardPreviewStyles';\n\n/**\n * Create the state required to render CardPreview.\n *\n * The returned state can be modified with hooks such as useCardPreviewStyles_unstable,\n * before being passed to renderCardPreview_unstable.\n *\n * @param props - props from this instance of CardPreview\n * @param ref - reference to root HTMLElement of CardPreview\n */\nexport const useCardPreview_unstable = (props: CardPreviewProps, ref: React.Ref<HTMLElement>): CardPreviewState => {\n const { logo } = props;\n\n const {\n selectableA11yProps: { referenceLabel, referenceId, setReferenceLabel, setReferenceId },\n } = useCardContext_unstable();\n const previewRef = useMergedRefs(ref, React.useRef<HTMLDivElement>(null));\n\n React.useEffect(() => {\n if (referenceLabel && referenceId) {\n return;\n }\n\n if (previewRef.current && previewRef.current.parentNode) {\n const img = previewRef.current.parentNode.querySelector<HTMLImageElement>(`.${cardPreviewClassNames.root} > img`);\n\n if (img) {\n const ariaLabel = img.getAttribute('aria-label');\n const ariaDescribedby = img.getAttribute('aria-describedby');\n\n if (ariaDescribedby) {\n setReferenceId(ariaDescribedby);\n } else if (img.alt) {\n setReferenceLabel(img.alt);\n } else if (ariaLabel) {\n setReferenceLabel(ariaLabel);\n }\n }\n }\n }, [setReferenceLabel, referenceLabel, previewRef, referenceId, setReferenceId]);\n\n return {\n components: {\n root: 'div',\n logo: 'div',\n },\n\n root: getNativeElementProps('div', {\n ref: previewRef,\n ...props,\n }),\n logo: resolveShorthand(logo),\n };\n};\n"],"sourceRoot":"../src/"}
|
package/lib/index.js
CHANGED
@@ -2,4 +2,5 @@ export { Card, cardClassNames, cardCSSVars, renderCard_unstable, useCardStyles_u
|
|
2
2
|
export { CardFooter, cardFooterClassNames, renderCardFooter_unstable, useCardFooterStyles_unstable, useCardFooter_unstable } from './CardFooter';
|
3
3
|
export { CardHeader, cardHeaderClassNames, cardHeaderCSSVars, renderCardHeader_unstable, useCardHeaderStyles_unstable, useCardHeader_unstable } from './CardHeader';
|
4
4
|
export { CardPreview, cardPreviewClassNames, renderCardPreview_unstable, useCardPreviewStyles_unstable, useCardPreview_unstable } from './CardPreview';
|
5
|
+
export { CardProvider, useCardContext_unstable } from './Card';
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-card/src/index.ts"],"names":[],"mappings":"AAAA,SACE,IADF,EAEE,cAFF,EAGE,WAHF,EAIE,mBAJF,EAKE,sBALF,EAME,gBANF,QAOO,QAPP;AASA,SACE,UADF,EAEE,oBAFF,EAGE,yBAHF,EAIE,4BAJF,EAKE,sBALF,QAMO,cANP;AAQA,SACE,UADF,EAEE,oBAFF,EAGE,iBAHF,EAIE,yBAJF,EAKE,4BALF,EAME,sBANF,QAOO,cAPP;AASA,SACE,WADF,EAEE,qBAFF,EAGE,0BAHF,EAIE,6BAJF,EAKE,uBALF,QAMO,eANP","sourcesContent":["export {\n Card,\n cardClassNames,\n cardCSSVars,\n renderCard_unstable,\n useCardStyles_unstable,\n useCard_unstable,\n} from './Card';\nexport type { CardProps, CardSlots, CardState,
|
1
|
+
{"version":3,"sources":["packages/react-components/react-card/src/index.ts"],"names":[],"mappings":"AAAA,SACE,IADF,EAEE,cAFF,EAGE,WAHF,EAIE,mBAJF,EAKE,sBALF,EAME,gBANF,QAOO,QAPP;AASA,SACE,UADF,EAEE,oBAFF,EAGE,yBAHF,EAIE,4BAJF,EAKE,sBALF,QAMO,cANP;AAQA,SACE,UADF,EAEE,oBAFF,EAGE,iBAHF,EAIE,yBAJF,EAKE,4BALF,EAME,sBANF,QAOO,cAPP;AASA,SACE,WADF,EAEE,qBAFF,EAGE,0BAHF,EAIE,6BAJF,EAKE,uBALF,QAMO,eANP;AAQA,SAAS,YAAT,EAAuB,uBAAvB,QAAsD,QAAtD","sourcesContent":["export {\n Card,\n cardClassNames,\n cardCSSVars,\n renderCard_unstable,\n useCardStyles_unstable,\n useCard_unstable,\n} from './Card';\nexport type { CardProps, CardSlots, CardState, CardOnSelectionChangeEvent } from './Card';\nexport {\n CardFooter,\n cardFooterClassNames,\n renderCardFooter_unstable,\n useCardFooterStyles_unstable,\n useCardFooter_unstable,\n} from './CardFooter';\nexport type { CardFooterProps, CardFooterSlots, CardFooterState } from './CardFooter';\nexport {\n CardHeader,\n cardHeaderClassNames,\n cardHeaderCSSVars,\n renderCardHeader_unstable,\n useCardHeaderStyles_unstable,\n useCardHeader_unstable,\n} from './CardHeader';\nexport type { CardHeaderProps, CardHeaderSlots, CardHeaderState } from './CardHeader';\nexport {\n CardPreview,\n cardPreviewClassNames,\n renderCardPreview_unstable,\n useCardPreviewStyles_unstable,\n useCardPreview_unstable,\n} from './CardPreview';\nexport type { CardPreviewProps, CardPreviewSlots, CardPreviewState } from './CardPreview';\nexport { CardProvider, useCardContext_unstable } from './Card';\nexport type { CardContextValue } from './Card';\n"],"sourceRoot":"../src/"}
|
@@ -12,6 +12,8 @@ const useCard_1 = /*#__PURE__*/require("./useCard");
|
|
12
12
|
const renderCard_1 = /*#__PURE__*/require("./renderCard");
|
13
13
|
|
14
14
|
const useCardStyles_1 = /*#__PURE__*/require("./useCardStyles");
|
15
|
+
|
16
|
+
const useCardContextValue_1 = /*#__PURE__*/require("./useCardContextValue");
|
15
17
|
/**
|
16
18
|
* A card provides scaffolding for hosting actions and content for a single topic.
|
17
19
|
*/
|
@@ -19,8 +21,9 @@ const useCardStyles_1 = /*#__PURE__*/require("./useCardStyles");
|
|
19
21
|
|
20
22
|
exports.Card = /*#__PURE__*/React.forwardRef((props, ref) => {
|
21
23
|
const state = useCard_1.useCard_unstable(props, ref);
|
24
|
+
const cardContextValue = useCardContextValue_1.useCardContextValue(state);
|
22
25
|
useCardStyles_1.useCardStyles_unstable(state);
|
23
|
-
return renderCard_1.renderCard_unstable(state);
|
26
|
+
return renderCard_1.renderCard_unstable(state, cardContextValue);
|
24
27
|
});
|
25
28
|
exports.Card.displayName = 'Card';
|
26
29
|
//# sourceMappingURL=Card.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/Card.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,SAAA,gBAAA,OAAA,CAAA,WAAA,CAAA;;AACA,MAAA,YAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;;AACA,MAAA,eAAA,gBAAA,OAAA,CAAA,iBAAA,CAAA;
|
1
|
+
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/Card.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,SAAA,gBAAA,OAAA,CAAA,WAAA,CAAA;;AACA,MAAA,YAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;;AACA,MAAA,eAAA,gBAAA,OAAA,CAAA,iBAAA,CAAA;;AAGA,MAAA,qBAAA,gBAAA,OAAA,CAAA,uBAAA,CAAA;AAEA;;AAEG;;;AACU,OAAA,CAAA,IAAA,gBAAuC,KAAK,CAAC,UAAN,CAAiC,CAAC,KAAD,EAAQ,GAAR,KAAe;EAClG,MAAM,KAAK,GAAG,SAAA,CAAA,gBAAA,CAAiB,KAAjB,EAAwB,GAAxB,CAAd;EACA,MAAM,gBAAgB,GAAG,qBAAA,CAAA,mBAAA,CAAoB,KAApB,CAAzB;EAEA,eAAA,CAAA,sBAAA,CAAuB,KAAvB;EACA,OAAO,YAAA,CAAA,mBAAA,CAAoB,KAApB,EAA2B,gBAA3B,CAAP;AACD,CANmD,CAAvC;AAQb,OAAA,CAAA,IAAA,CAAK,WAAL,GAAmB,MAAnB","sourcesContent":["import * as React from 'react';\nimport { useCard_unstable } from './useCard';\nimport { renderCard_unstable } from './renderCard';\nimport { useCardStyles_unstable } from './useCardStyles';\nimport type { CardProps } from './Card.types';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\nimport { useCardContextValue } from './useCardContextValue';\n\n/**\n * A card provides scaffolding for hosting actions and content for a single topic.\n */\nexport const Card: ForwardRefComponent<CardProps> = React.forwardRef<HTMLDivElement>((props, ref) => {\n const state = useCard_unstable(props, ref);\n const cardContextValue = useCardContextValue(state);\n\n useCardStyles_unstable(state);\n return renderCard_unstable(state, cardContextValue);\n});\n\nCard.displayName = 'Card';\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useCardContext_unstable = exports.CardProvider = exports.cardContextDefaultValue = void 0;
|
7
|
+
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
|
+
|
10
|
+
const cardContext = /*#__PURE__*/React.createContext(undefined);
|
11
|
+
/**
|
12
|
+
* @internal
|
13
|
+
*/
|
14
|
+
|
15
|
+
exports.cardContextDefaultValue = {
|
16
|
+
selectableA11yProps: {
|
17
|
+
referenceId: undefined,
|
18
|
+
|
19
|
+
setReferenceId() {
|
20
|
+
/* Noop */
|
21
|
+
},
|
22
|
+
|
23
|
+
referenceLabel: undefined,
|
24
|
+
|
25
|
+
setReferenceLabel() {
|
26
|
+
/* Noop */
|
27
|
+
}
|
28
|
+
|
29
|
+
}
|
30
|
+
};
|
31
|
+
/**
|
32
|
+
* @internal
|
33
|
+
*/
|
34
|
+
|
35
|
+
exports.CardProvider = cardContext.Provider;
|
36
|
+
/**
|
37
|
+
* @internal
|
38
|
+
*/
|
39
|
+
|
40
|
+
const useCardContext_unstable = () => {
|
41
|
+
var _a;
|
42
|
+
|
43
|
+
return (_a = React.useContext(cardContext)) !== null && _a !== void 0 ? _a : exports.cardContextDefaultValue;
|
44
|
+
};
|
45
|
+
|
46
|
+
exports.useCardContext_unstable = useCardContext_unstable;
|
47
|
+
//# sourceMappingURL=CardContext.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/CardContext.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AAGA,MAAM,WAAW,gBAAG,KAAK,CAAC,aAAN,CAAkD,SAAlD,CAApB;AAEA;;AAEG;;AACU,OAAA,CAAA,uBAAA,GAA4C;EACvD,mBAAmB,EAAE;IACnB,WAAW,EAAE,SADM;;IAEnB,cAAc,GAAA;MACZ;IACD,CAJkB;;IAKnB,cAAc,EAAE,SALG;;IAMnB,iBAAiB,GAAA;MACf;IACD;;EARkB;AADkC,CAA5C;AAab;;AAEG;;AACU,OAAA,CAAA,YAAA,GAAe,WAAW,CAAC,QAA3B;AAEb;;AAEG;;AACI,MAAM,uBAAuB,GAAG,MAAK;EAAA,IAAA,EAAA;;EAAC,OAAA,CAAA,EAAA,GAAA,KAAK,CAAC,UAAN,CAAiB,WAAjB,CAAA,MAA6B,IAA7B,IAA6B,EAAA,KAAA,KAAA,CAA7B,GAA6B,EAA7B,GAAiC,OAAA,CAAA,uBAAjC;AAAwD,CAA9F;;AAAM,OAAA,CAAA,uBAAA,GAAuB,uBAAvB","sourcesContent":["import * as React from 'react';\nimport { CardContextValue } from './Card.types';\n\nconst cardContext = React.createContext<CardContextValue | undefined>(undefined);\n\n/**\n * @internal\n */\nexport const cardContextDefaultValue: CardContextValue = {\n selectableA11yProps: {\n referenceId: undefined,\n setReferenceId() {\n /* Noop */\n },\n referenceLabel: undefined,\n setReferenceLabel() {\n /* Noop */\n },\n },\n};\n\n/**\n * @internal\n */\nexport const CardProvider = cardContext.Provider;\n\n/**\n * @internal\n */\nexport const useCardContext_unstable = () => React.useContext(cardContext) ?? cardContextDefaultValue;\n"],"sourceRoot":"../src/"}
|
@@ -10,6 +10,8 @@ tslib_1.__exportStar(require("./Card"), exports);
|
|
10
10
|
|
11
11
|
tslib_1.__exportStar(require("./Card.types"), exports);
|
12
12
|
|
13
|
+
tslib_1.__exportStar(require("./CardContext"), exports);
|
14
|
+
|
13
15
|
tslib_1.__exportStar(require("./renderCard"), exports);
|
14
16
|
|
15
17
|
tslib_1.__exportStar(require("./useCard"), exports);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,QAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,WAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './Card';\nexport * from './Card.types';\nexport * from './renderCard';\nexport * from './useCard';\nexport * from './useCardStyles';\n"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,QAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,eAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,WAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './Card';\nexport * from './Card.types';\nexport * from './CardContext';\nexport * from './renderCard';\nexport * from './useCard';\nexport * from './useCardStyles';\n"],"sourceRoot":"../src/"}
|
@@ -8,19 +8,24 @@ exports.renderCard_unstable = void 0;
|
|
8
8
|
const React = /*#__PURE__*/require("react");
|
9
9
|
|
10
10
|
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
11
|
+
|
12
|
+
const CardContext_1 = /*#__PURE__*/require("./CardContext");
|
11
13
|
/**
|
12
14
|
* Render the final JSX of Card.
|
13
15
|
*/
|
14
16
|
|
15
17
|
|
16
|
-
const renderCard_unstable = state => {
|
18
|
+
const renderCard_unstable = (state, cardContextValue) => {
|
17
19
|
const {
|
18
20
|
slots,
|
19
21
|
slotProps
|
20
22
|
} = react_utilities_1.getSlots(state);
|
21
23
|
return React.createElement(slots.root, { ...slotProps.root
|
22
|
-
},
|
23
|
-
|
24
|
+
}, React.createElement(CardContext_1.CardProvider, {
|
25
|
+
value: cardContextValue
|
26
|
+
}, slots.checkbox ? React.createElement(slots.checkbox, { ...slotProps.checkbox
|
27
|
+
}) : null, slots.floatingAction ? React.createElement(slots.floatingAction, { ...slotProps.floatingAction
|
28
|
+
}) : null, slotProps.root.children));
|
24
29
|
};
|
25
30
|
|
26
31
|
exports.renderCard_unstable = renderCard_unstable;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/renderCard.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;
|
1
|
+
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/renderCard.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AAEA,MAAA,aAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;AAEA;;AAEG;;;AACI,MAAM,mBAAmB,GAAG,CAAC,KAAD,EAAmB,gBAAnB,KAAyD;EAC1F,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,iBAAA,CAAA,QAAA,CAAoB,KAApB,CAA7B;EAEA,OACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;EAAf,CAAX,EACE,KAAA,CAAA,aAAA,CAAC,aAAA,CAAA,YAAD,EAAa;IAAC,KAAK,EAAE;EAAR,CAAb,EACG,KAAK,CAAC,QAAN,GAAiB,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,QAAP,EAAe,EAAA,GAAK,SAAS,CAAC;EAAf,CAAf,CAAjB,GAA8D,IADjE,EAEG,KAAK,CAAC,cAAN,GAAuB,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,cAAP,EAAqB,EAAA,GAAK,SAAS,CAAC;EAAf,CAArB,CAAvB,GAAgF,IAFnF,EAGG,SAAS,CAAC,IAAV,CAAe,QAHlB,CADF,CADF;AASD,CAZM;;AAAM,OAAA,CAAA,mBAAA,GAAmB,mBAAnB","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { CardContextValue, CardSlots, CardState } from './Card.types';\nimport { CardProvider } from './CardContext';\n\n/**\n * Render the final JSX of Card.\n */\nexport const renderCard_unstable = (state: CardState, cardContextValue: CardContextValue) => {\n const { slots, slotProps } = getSlots<CardSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n <CardProvider value={cardContextValue}>\n {slots.checkbox ? <slots.checkbox {...slotProps.checkbox} /> : null}\n {slots.floatingAction ? <slots.floatingAction {...slotProps.floatingAction} /> : null}\n {slotProps.root.children}\n </CardProvider>\n </slots.root>\n );\n};\n"],"sourceRoot":"../src/"}
|
@@ -13,30 +13,38 @@ const react_tabster_1 = /*#__PURE__*/require("@fluentui/react-tabster");
|
|
13
13
|
|
14
14
|
const useCardSelectable_1 = /*#__PURE__*/require("./useCardSelectable");
|
15
15
|
|
16
|
+
const CardContext_1 = /*#__PURE__*/require("./CardContext");
|
17
|
+
|
16
18
|
const focusMap = {
|
17
19
|
off: undefined,
|
18
20
|
'no-tab': 'limited-trap-focus',
|
19
21
|
'tab-exit': 'limited',
|
20
22
|
'tab-only': 'unlimited'
|
21
23
|
};
|
24
|
+
/**
|
25
|
+
* Create the state for interactive cards.
|
26
|
+
*
|
27
|
+
* This internal hook defines if the card is interactive
|
28
|
+
* and control focus properties based on that.
|
29
|
+
*
|
30
|
+
* @param props - props from this instance of Card
|
31
|
+
*/
|
22
32
|
|
23
|
-
const
|
24
|
-
focusMode = 'off'
|
25
|
-
|
26
|
-
interactive
|
33
|
+
const useCardInteractive = ({
|
34
|
+
focusMode = 'off',
|
35
|
+
...props
|
27
36
|
}) => {
|
28
|
-
const
|
37
|
+
const interactive = ['onClick', 'onDoubleClick', 'onMouseUp', 'onMouseDown', 'onPointerUp', 'onPointerDown', 'onTouchStart', 'onTouchEnd', 'onDragStart', 'onDragEnd'].some(prop => props[prop]);
|
29
38
|
const groupperAttrs = react_tabster_1.useFocusableGroup({
|
30
|
-
tabBehavior: focusMap[
|
39
|
+
tabBehavior: focusMap[interactive ? 'no-tab' : focusMode]
|
31
40
|
});
|
32
|
-
|
33
|
-
if (internalFocusMode === 'off') {
|
34
|
-
return null;
|
35
|
-
}
|
36
|
-
|
37
|
-
return { ...groupperAttrs,
|
41
|
+
const interactiveFocusAttributes = { ...groupperAttrs,
|
38
42
|
tabIndex: 0
|
39
43
|
};
|
44
|
+
return {
|
45
|
+
interactive,
|
46
|
+
focusAttributes: focusMode === 'off' ? null : interactiveFocusAttributes
|
47
|
+
};
|
40
48
|
};
|
41
49
|
/**
|
42
50
|
* Create the state required to render Card.
|
@@ -54,40 +62,54 @@ const useCard_unstable = (props, ref) => {
|
|
54
62
|
appearance = 'filled',
|
55
63
|
orientation = 'vertical',
|
56
64
|
size = 'medium',
|
57
|
-
|
65
|
+
floatingAction
|
58
66
|
} = props;
|
59
|
-
const
|
67
|
+
const [referenceId, setReferenceId] = React.useState(CardContext_1.cardContextDefaultValue.selectableA11yProps.referenceId);
|
68
|
+
const [referenceLabel, setReferenceLabel] = React.useState(CardContext_1.cardContextDefaultValue.selectableA11yProps.referenceId);
|
69
|
+
const cardBaseRef = react_tabster_1.useFocusWithin();
|
60
70
|
const {
|
61
71
|
selectable,
|
62
|
-
hasSelectSlot,
|
63
72
|
selected,
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
});
|
73
|
+
selectableCardProps,
|
74
|
+
selectFocused,
|
75
|
+
checkboxSlot
|
76
|
+
} = useCardSelectable_1.useCardSelectable(props, {
|
77
|
+
referenceId,
|
78
|
+
referenceLabel
|
79
|
+
}, cardBaseRef);
|
80
|
+
const cardRef = react_utilities_1.useMergedRefs(cardBaseRef, ref);
|
81
|
+
const {
|
82
|
+
interactive,
|
83
|
+
focusAttributes
|
84
|
+
} = useCardInteractive(props);
|
71
85
|
return {
|
72
86
|
appearance,
|
73
87
|
orientation,
|
74
88
|
size,
|
75
89
|
interactive,
|
76
90
|
selectable,
|
77
|
-
|
91
|
+
selectFocused,
|
78
92
|
selected,
|
93
|
+
selectableA11yProps: {
|
94
|
+
setReferenceId,
|
95
|
+
referenceId,
|
96
|
+
referenceLabel,
|
97
|
+
setReferenceLabel
|
98
|
+
},
|
79
99
|
components: {
|
80
|
-
root:
|
81
|
-
|
100
|
+
root: 'div',
|
101
|
+
floatingAction: 'div',
|
102
|
+
checkbox: 'input'
|
82
103
|
},
|
83
|
-
root: react_utilities_1.getNativeElementProps(
|
84
|
-
ref:
|
104
|
+
root: react_utilities_1.getNativeElementProps('div', {
|
105
|
+
ref: cardRef,
|
85
106
|
role: 'group',
|
86
107
|
...focusAttributes,
|
87
108
|
...props,
|
88
|
-
...
|
109
|
+
...selectableCardProps
|
89
110
|
}),
|
90
|
-
|
111
|
+
floatingAction: react_utilities_1.resolveShorthand(floatingAction),
|
112
|
+
checkbox: checkboxSlot
|
91
113
|
};
|
92
114
|
};
|
93
115
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/useCard.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AACA,MAAA,eAAA,gBAAA,OAAA,CAAA,yBAAA,CAA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;MAGjC,GAAG,eAH8B;MAIjC,GAAG,KAJ8B;MAKjC,GAAG;IAL8B,CAA7B,CArBD;IA6BL,cAAc,EAAE,iBAAA,CAAA,gBAAA,CAAiB,cAAjB,CA7BX;IA8BL,QAAQ,EAAE;EA9BL,CAAP;AAgCD,CAjDM;;AAAM,OAAA,CAAA,gBAAA,GAAgB,gBAAhB","sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, resolveShorthand, useMergedRefs } from '@fluentui/react-utilities';\nimport { useFocusableGroup, useFocusWithin } from '@fluentui/react-tabster';\n\nimport type { CardProps, CardState } from './Card.types';\nimport { useCardSelectable } from './useCardSelectable';\nimport { cardContextDefaultValue } from './CardContext';\n\nconst focusMap = {\n off: undefined,\n 'no-tab': 'limited-trap-focus',\n 'tab-exit': 'limited',\n 'tab-only': 'unlimited',\n} as const;\n\n/**\n * Create the state for interactive cards.\n *\n * This internal hook defines if the card is interactive\n * and control focus properties based on that.\n *\n * @param props - props from this instance of Card\n */\nconst useCardInteractive = ({ focusMode = 'off', ...props }: CardProps) => {\n const interactive = ([\n 'onClick',\n 'onDoubleClick',\n 'onMouseUp',\n 'onMouseDown',\n 'onPointerUp',\n 'onPointerDown',\n 'onTouchStart',\n 'onTouchEnd',\n 'onDragStart',\n 'onDragEnd',\n ] as (keyof React.HTMLAttributes<HTMLElement>)[]).some(prop => props[prop]);\n\n const groupperAttrs = useFocusableGroup({\n tabBehavior: focusMap[interactive ? 'no-tab' : focusMode],\n });\n\n const interactiveFocusAttributes = {\n ...groupperAttrs,\n tabIndex: 0,\n };\n\n return {\n interactive,\n focusAttributes: focusMode === 'off' ? null : interactiveFocusAttributes,\n };\n};\n\n/**\n * Create the state required to render Card.\n *\n * The returned state can be modified with hooks such as useCardStyles_unstable,\n * before being passed to renderCard_unstable.\n *\n * @param props - props from this instance of Card\n * @param ref - reference to the root element of Card\n */\nexport const useCard_unstable = (props: CardProps, ref: React.Ref<HTMLDivElement>): CardState => {\n const { appearance = 'filled', orientation = 'vertical', size = 'medium', floatingAction } = props;\n\n const [referenceId, setReferenceId] = React.useState(cardContextDefaultValue.selectableA11yProps.referenceId);\n const [referenceLabel, setReferenceLabel] = React.useState(cardContextDefaultValue.selectableA11yProps.referenceId);\n\n const cardBaseRef = useFocusWithin<HTMLDivElement>();\n const { selectable, selected, selectableCardProps, selectFocused, checkboxSlot } = useCardSelectable(\n props,\n { referenceId, referenceLabel },\n cardBaseRef,\n );\n\n const cardRef = useMergedRefs(cardBaseRef, ref);\n\n const { interactive, focusAttributes } = useCardInteractive(props);\n\n return {\n appearance,\n orientation,\n size,\n interactive,\n selectable,\n selectFocused,\n selected,\n selectableA11yProps: {\n setReferenceId,\n referenceId,\n referenceLabel,\n setReferenceLabel,\n },\n\n components: {\n root: 'div',\n floatingAction: 'div',\n checkbox: 'input',\n },\n\n root: getNativeElementProps('div', {\n ref: cardRef,\n role: 'group',\n ...focusAttributes,\n ...props,\n ...selectableCardProps,\n }),\n\n floatingAction: resolveShorthand(floatingAction),\n checkbox: checkboxSlot,\n };\n};\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useCardContextValue = void 0;
|
7
|
+
|
8
|
+
function useCardContextValue({
|
9
|
+
selectableA11yProps
|
10
|
+
}) {
|
11
|
+
return {
|
12
|
+
selectableA11yProps
|
13
|
+
};
|
14
|
+
}
|
15
|
+
|
16
|
+
exports.useCardContextValue = useCardContextValue;
|
17
|
+
//# sourceMappingURL=useCardContextValue.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/useCardContextValue.ts"],"names":[],"mappings":";;;;;;;AAEA,SAAgB,mBAAhB,CAAoC;EAAE;AAAF,CAApC,EAAsE;EACpE,OAAO;IAAE;EAAF,CAAP;AACD;;AAFD,OAAA,CAAA,mBAAA,GAAA,mBAAA","sourcesContent":["import type { CardContextValue, CardState } from './Card.types';\n\nexport function useCardContextValue({ selectableA11yProps }: CardState): CardContextValue {\n return { selectableA11yProps };\n}\n"],"sourceRoot":"../src/"}
|
@@ -12,33 +12,50 @@ const keyboard_keys_1 = /*#__PURE__*/require("@fluentui/keyboard-keys");
|
|
12
12
|
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
13
13
|
|
14
14
|
const react_tabster_1 = /*#__PURE__*/require("@fluentui/react-tabster");
|
15
|
+
/**
|
16
|
+
* @internal
|
17
|
+
*
|
18
|
+
* Create the state related to selectable cards.
|
19
|
+
*
|
20
|
+
* This internal hook controls all the logic for selectable cards and is
|
21
|
+
* intended to be used alongside with useCard_unstable.
|
22
|
+
*
|
23
|
+
* @param props - props from this instance of Card
|
24
|
+
* @param a11yProps - accessibility props shared between elements of the card
|
25
|
+
* @param ref - reference to the root element of Card
|
26
|
+
*/
|
15
27
|
|
16
|
-
|
28
|
+
|
29
|
+
const useCardSelectable = (props, {
|
30
|
+
referenceLabel,
|
31
|
+
referenceId
|
32
|
+
}, cardRef) => {
|
17
33
|
const {
|
18
|
-
|
34
|
+
checkbox = {},
|
19
35
|
selected,
|
20
36
|
defaultSelected,
|
21
|
-
onSelectionChange
|
37
|
+
onSelectionChange,
|
38
|
+
floatingAction,
|
39
|
+
onClick,
|
40
|
+
onKeyDown
|
22
41
|
} = props;
|
23
42
|
const {
|
24
43
|
findAllFocusable
|
25
44
|
} = react_tabster_1.useFocusFinders();
|
26
|
-
const
|
27
|
-
const isSelectable = [selected, defaultSelected, onSelectionChange
|
28
|
-
const hasSelectSlot = Boolean(select);
|
45
|
+
const checkboxRef = React.useRef(null);
|
46
|
+
const isSelectable = [selected, defaultSelected, onSelectionChange].some(prop => typeof prop !== 'undefined');
|
29
47
|
const [isCardSelected, setIsCardSelected] = React.useState(false);
|
48
|
+
const [isSelectFocused, setIsSelectFocused] = React.useState(false);
|
30
49
|
const shouldRestrictTriggerAction = React.useCallback(event => {
|
31
|
-
var _a;
|
32
|
-
|
33
50
|
if (!cardRef.current) {
|
34
51
|
return false;
|
35
52
|
}
|
36
53
|
|
37
54
|
const focusableElements = findAllFocusable(cardRef.current);
|
38
55
|
const target = event.target;
|
39
|
-
const
|
40
|
-
const
|
41
|
-
return
|
56
|
+
const isElementInFocusableGroup = focusableElements.some(element => element.contains(target));
|
57
|
+
const isCheckboxSlot = (checkboxRef === null || checkboxRef === void 0 ? void 0 : checkboxRef.current) === target;
|
58
|
+
return isElementInFocusableGroup && !isCheckboxSlot;
|
42
59
|
}, [cardRef, findAllFocusable]);
|
43
60
|
const onChangeHandler = React.useCallback(event => {
|
44
61
|
if (shouldRestrictTriggerAction(event)) {
|
@@ -60,42 +77,48 @@ const useCardSelectable = (props, cardRef) => {
|
|
60
77
|
onChangeHandler(event);
|
61
78
|
}
|
62
79
|
}, [onChangeHandler]);
|
63
|
-
const
|
64
|
-
if (!isSelectable) {
|
65
|
-
return
|
80
|
+
const checkboxSlot = React.useMemo(() => {
|
81
|
+
if (!isSelectable || !!floatingAction) {
|
82
|
+
return;
|
66
83
|
}
|
67
84
|
|
68
|
-
const
|
69
|
-
onClick: onChangeHandler,
|
70
|
-
onKeyDown: onKeyDownHandler
|
71
|
-
};
|
85
|
+
const selectableCheckboxProps = {};
|
72
86
|
|
73
|
-
if (
|
74
|
-
|
75
|
-
|
76
|
-
|
87
|
+
if (referenceId) {
|
88
|
+
selectableCheckboxProps['aria-labelledby'] = referenceId;
|
89
|
+
} else if (referenceLabel) {
|
90
|
+
selectableCheckboxProps['aria-label'] = referenceLabel;
|
77
91
|
}
|
78
92
|
|
79
|
-
return
|
80
|
-
}, [hasSelectSlot, isCardSelected, isSelectable, onChangeHandler, onKeyDownHandler]);
|
81
|
-
const selectableSlot = React.useMemo(() => {
|
82
|
-
if (!hasSelectSlot) {
|
83
|
-
return undefined;
|
84
|
-
}
|
85
|
-
|
86
|
-
return react_utilities_1.resolveShorthand(select, {
|
93
|
+
return react_utilities_1.resolveShorthand(checkbox, {
|
87
94
|
defaultProps: {
|
88
|
-
ref:
|
95
|
+
ref: checkboxRef,
|
96
|
+
type: 'checkbox',
|
97
|
+
checked: isCardSelected,
|
98
|
+
onChange: event => onChangeHandler(event),
|
99
|
+
onFocus: () => setIsSelectFocused(true),
|
100
|
+
onBlur: () => setIsSelectFocused(false),
|
101
|
+
...selectableCheckboxProps
|
89
102
|
}
|
90
103
|
});
|
91
|
-
}, [
|
104
|
+
}, [isSelectable, floatingAction, referenceId, referenceLabel, checkbox, isCardSelected, onChangeHandler]);
|
105
|
+
const selectableCardProps = React.useMemo(() => {
|
106
|
+
if (!isSelectable) {
|
107
|
+
return null;
|
108
|
+
}
|
109
|
+
|
110
|
+
return {
|
111
|
+
onClick: react_utilities_1.mergeCallbacks(onClick, onChangeHandler),
|
112
|
+
onKeyDown: react_utilities_1.mergeCallbacks(onKeyDown, onKeyDownHandler)
|
113
|
+
};
|
114
|
+
}, [isSelectable, onChangeHandler, onClick, onKeyDown, onKeyDownHandler]);
|
92
115
|
React.useEffect(() => setIsCardSelected(Boolean(defaultSelected !== null && defaultSelected !== void 0 ? defaultSelected : selected)), [defaultSelected, selected, setIsCardSelected]);
|
93
116
|
return {
|
94
117
|
selected: isCardSelected,
|
95
118
|
selectable: isSelectable,
|
96
|
-
|
97
|
-
|
98
|
-
|
119
|
+
selectFocused: isSelectFocused,
|
120
|
+
selectableCardProps,
|
121
|
+
checkboxSlot
|
99
122
|
};
|
100
123
|
};
|
101
124
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/useCardSelectable.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,eAAA,gBAAA,OAAA,CAAA,yBAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AACA,MAAA,eAAA,gBAAA,OAAA,CAAA,yBA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,CAAP;AAOD,CA7GM;;AAAM,OAAA,CAAA,iBAAA,GAAiB,iBAAjB","sourcesContent":["import * as React from 'react';\nimport { Enter, Space } from '@fluentui/keyboard-keys';\nimport { mergeCallbacks, resolveShorthand } from '@fluentui/react-utilities';\nimport { useFocusFinders } from '@fluentui/react-tabster';\n\nimport type { CardContextValue, CardOnSelectionChangeEvent, CardProps, CardSlots } from './Card.types';\n\n/**\n * @internal\n *\n * Create the state related to selectable cards.\n *\n * This internal hook controls all the logic for selectable cards and is\n * intended to be used alongside with useCard_unstable.\n *\n * @param props - props from this instance of Card\n * @param a11yProps - accessibility props shared between elements of the card\n * @param ref - reference to the root element of Card\n */\nexport const useCardSelectable = (\n props: CardProps,\n { referenceLabel, referenceId }: Pick<CardContextValue['selectableA11yProps'], 'referenceId' | 'referenceLabel'>,\n cardRef: React.RefObject<HTMLDivElement>,\n) => {\n const { checkbox = {}, selected, defaultSelected, onSelectionChange, floatingAction, onClick, onKeyDown } = props;\n\n const { findAllFocusable } = useFocusFinders();\n\n const checkboxRef = React.useRef<HTMLInputElement>(null);\n\n const isSelectable = [selected, defaultSelected, onSelectionChange].some(prop => typeof prop !== 'undefined');\n\n const [isCardSelected, setIsCardSelected] = React.useState(false);\n const [isSelectFocused, setIsSelectFocused] = React.useState(false);\n\n const shouldRestrictTriggerAction = React.useCallback(\n (event: CardOnSelectionChangeEvent) => {\n if (!cardRef.current) {\n return false;\n }\n\n const focusableElements = findAllFocusable(cardRef.current);\n const target = event.target as HTMLElement;\n const isElementInFocusableGroup = focusableElements.some(element => element.contains(target));\n const isCheckboxSlot = checkboxRef?.current === target;\n\n return isElementInFocusableGroup && !isCheckboxSlot;\n },\n [cardRef, findAllFocusable],\n );\n\n const onChangeHandler = React.useCallback(\n (event: CardOnSelectionChangeEvent) => {\n if (shouldRestrictTriggerAction(event)) {\n return;\n }\n\n const newCheckedValue = !isCardSelected;\n\n setIsCardSelected(newCheckedValue);\n\n if (onSelectionChange) {\n onSelectionChange(event, { selected: newCheckedValue });\n }\n },\n [onSelectionChange, isCardSelected, shouldRestrictTriggerAction],\n );\n\n const onKeyDownHandler = React.useCallback(\n (event: React.KeyboardEvent<HTMLElement>) => {\n if ([Enter, Space].includes(event.key)) {\n event.preventDefault();\n onChangeHandler(event);\n }\n },\n [onChangeHandler],\n );\n\n const checkboxSlot = React.useMemo(() => {\n if (!isSelectable || !!floatingAction) {\n return;\n }\n\n const selectableCheckboxProps: CardSlots['checkbox'] = {};\n\n if (referenceId) {\n selectableCheckboxProps['aria-labelledby'] = referenceId;\n } else if (referenceLabel) {\n selectableCheckboxProps['aria-label'] = referenceLabel;\n }\n\n return resolveShorthand(checkbox, {\n defaultProps: {\n ref: checkboxRef,\n type: 'checkbox',\n checked: isCardSelected,\n onChange: (event: React.ChangeEvent<HTMLInputElement>) => onChangeHandler(event),\n onFocus: () => setIsSelectFocused(true),\n onBlur: () => setIsSelectFocused(false),\n ...selectableCheckboxProps,\n },\n });\n }, [isSelectable, floatingAction, referenceId, referenceLabel, checkbox, isCardSelected, onChangeHandler]);\n\n const selectableCardProps = React.useMemo(() => {\n if (!isSelectable) {\n return null;\n }\n\n return {\n onClick: mergeCallbacks(onClick, onChangeHandler),\n onKeyDown: mergeCallbacks(onKeyDown, onKeyDownHandler),\n };\n }, [isSelectable, onChangeHandler, onClick, onKeyDown, onKeyDownHandler]);\n\n React.useEffect(() => setIsCardSelected(Boolean(defaultSelected ?? selected)), [\n defaultSelected,\n selected,\n setIsCardSelected,\n ]);\n\n return {\n selected: isCardSelected,\n selectable: isSelectable,\n selectFocused: isSelectFocused,\n selectableCardProps,\n checkboxSlot,\n };\n};\n"],"sourceRoot":"../src/"}
|