@fluentui/react-card 9.0.0-beta.30 → 9.0.0-beta.32
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 +105 -1
- package/CHANGELOG.md +31 -2
- package/dist/index.d.ts +85 -4
- package/lib/components/Card/Card.js.map +1 -1
- package/lib/components/Card/Card.types.js.map +1 -1
- package/lib/components/Card/renderCard.js +2 -1
- package/lib/components/Card/renderCard.js.map +1 -1
- package/lib/components/Card/useCard.js +55 -21
- package/lib/components/Card/useCard.js.map +1 -1
- package/lib/components/Card/useCardSelectable.js +90 -0
- package/lib/components/Card/useCardSelectable.js.map +1 -0
- package/lib/components/Card/useCardStyles.js +139 -50
- package/lib/components/Card/useCardStyles.js.map +1 -1
- package/lib/components/CardHeader/useCardHeaderStyles.js +2 -1
- package/lib/components/CardHeader/useCardHeaderStyles.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib-commonjs/components/Card/Card.js.map +1 -1
- package/lib-commonjs/components/Card/renderCard.js +2 -1
- package/lib-commonjs/components/Card/renderCard.js.map +1 -1
- package/lib-commonjs/components/Card/useCard.js +57 -21
- package/lib-commonjs/components/Card/useCard.js.map +1 -1
- package/lib-commonjs/components/Card/useCardSelectable.js +103 -0
- package/lib-commonjs/components/Card/useCardSelectable.js.map +1 -0
- package/lib-commonjs/components/Card/useCardStyles.js +140 -51
- package/lib-commonjs/components/Card/useCardStyles.js.map +1 -1
- package/lib-commonjs/components/CardHeader/useCardHeaderStyles.js +2 -1
- package/lib-commonjs/components/CardHeader/useCardHeaderStyles.js.map +1 -1
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +9 -9
package/CHANGELOG.json
CHANGED
@@ -2,7 +2,111 @@
|
|
2
2
|
"name": "@fluentui/react-card",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "
|
5
|
+
"date": "Fri, 11 Nov 2022 14:53:43 GMT",
|
6
|
+
"tag": "@fluentui/react-card_v9.0.0-beta.32",
|
7
|
+
"version": "9.0.0-beta.32",
|
8
|
+
"comments": {
|
9
|
+
"prerelease": [
|
10
|
+
{
|
11
|
+
"author": "marcosvmmoura@gmail.com",
|
12
|
+
"package": "@fluentui/react-card",
|
13
|
+
"commit": "7c951efddfb820f51d6a52a8f994f1c1c712698a",
|
14
|
+
"comment": "feat: add selectable feature to card"
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"author": "beachball",
|
18
|
+
"package": "@fluentui/react-card",
|
19
|
+
"comment": "Bump @fluentui/keyboard-keys to v9.0.1",
|
20
|
+
"commit": "b4c9a0ae8d7444bf746f1307ab01e2dc16310720"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"author": "beachball",
|
24
|
+
"package": "@fluentui/react-card",
|
25
|
+
"comment": "Bump @fluentui/react-tabster to v9.3.0",
|
26
|
+
"commit": "b4c9a0ae8d7444bf746f1307ab01e2dc16310720"
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"author": "beachball",
|
30
|
+
"package": "@fluentui/react-card",
|
31
|
+
"comment": "Bump @fluentui/react-theme to v9.1.2",
|
32
|
+
"commit": "b4c9a0ae8d7444bf746f1307ab01e2dc16310720"
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"author": "beachball",
|
36
|
+
"package": "@fluentui/react-card",
|
37
|
+
"comment": "Bump @fluentui/react-utilities to v9.2.1",
|
38
|
+
"commit": "b4c9a0ae8d7444bf746f1307ab01e2dc16310720"
|
39
|
+
},
|
40
|
+
{
|
41
|
+
"author": "beachball",
|
42
|
+
"package": "@fluentui/react-card",
|
43
|
+
"comment": "Bump @fluentui/react-conformance-griffel to v9.0.0-beta.18",
|
44
|
+
"commit": "b4c9a0ae8d7444bf746f1307ab01e2dc16310720"
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"author": "beachball",
|
48
|
+
"package": "@fluentui/react-card",
|
49
|
+
"comment": "Bump @fluentui/react-button to v9.1.8",
|
50
|
+
"commit": "b4c9a0ae8d7444bf746f1307ab01e2dc16310720"
|
51
|
+
}
|
52
|
+
],
|
53
|
+
"none": [
|
54
|
+
{
|
55
|
+
"author": "martinhochel@microsoft.com",
|
56
|
+
"package": "@fluentui/react-card",
|
57
|
+
"commit": "87859b052155ca206ef3540a2a9623803f6e2b93",
|
58
|
+
"comment": "test: replace deprecated module.parent with require.main within isConformance"
|
59
|
+
}
|
60
|
+
]
|
61
|
+
}
|
62
|
+
},
|
63
|
+
{
|
64
|
+
"date": "Wed, 02 Nov 2022 11:57:49 GMT",
|
65
|
+
"tag": "@fluentui/react-card_v9.0.0-beta.31",
|
66
|
+
"version": "9.0.0-beta.31",
|
67
|
+
"comments": {
|
68
|
+
"prerelease": [
|
69
|
+
{
|
70
|
+
"author": "olfedias@microsoft.com",
|
71
|
+
"package": "@fluentui/react-card",
|
72
|
+
"commit": "c619ba066f11a8654e95375314824ba6b81b003e",
|
73
|
+
"comment": "chore: Update Griffel to latest version"
|
74
|
+
},
|
75
|
+
{
|
76
|
+
"author": "beachball",
|
77
|
+
"package": "@fluentui/react-card",
|
78
|
+
"comment": "Bump @fluentui/react-utilities to v9.2.0",
|
79
|
+
"commit": "393a7b169155997a97a6ce1ad36ee3eafc6f461b"
|
80
|
+
},
|
81
|
+
{
|
82
|
+
"author": "beachball",
|
83
|
+
"package": "@fluentui/react-card",
|
84
|
+
"comment": "Bump @fluentui/react-tabster to v9.2.1",
|
85
|
+
"commit": "393a7b169155997a97a6ce1ad36ee3eafc6f461b"
|
86
|
+
},
|
87
|
+
{
|
88
|
+
"author": "beachball",
|
89
|
+
"package": "@fluentui/react-card",
|
90
|
+
"comment": "Bump @fluentui/react-conformance-griffel to v9.0.0-beta.17",
|
91
|
+
"commit": "393a7b169155997a97a6ce1ad36ee3eafc6f461b"
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"author": "beachball",
|
95
|
+
"package": "@fluentui/react-card",
|
96
|
+
"comment": "Bump @fluentui/react-text to v9.1.5",
|
97
|
+
"commit": "393a7b169155997a97a6ce1ad36ee3eafc6f461b"
|
98
|
+
},
|
99
|
+
{
|
100
|
+
"author": "beachball",
|
101
|
+
"package": "@fluentui/react-card",
|
102
|
+
"comment": "Bump @fluentui/react-button to v9.1.7",
|
103
|
+
"commit": "393a7b169155997a97a6ce1ad36ee3eafc6f461b"
|
104
|
+
}
|
105
|
+
]
|
106
|
+
}
|
107
|
+
},
|
108
|
+
{
|
109
|
+
"date": "Tue, 25 Oct 2022 00:35:40 GMT",
|
6
110
|
"tag": "@fluentui/react-card_v9.0.0-beta.30",
|
7
111
|
"version": "9.0.0-beta.30",
|
8
112
|
"comments": {
|
package/CHANGELOG.md
CHANGED
@@ -1,12 +1,41 @@
|
|
1
1
|
# Change Log - @fluentui/react-card
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Fri, 11 Nov 2022 14:53:43 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
+
## [9.0.0-beta.32](https://github.com/microsoft/fluentui/tree/@fluentui/react-card_v9.0.0-beta.32)
|
8
|
+
|
9
|
+
Fri, 11 Nov 2022 14:53:43 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-card_v9.0.0-beta.31..@fluentui/react-card_v9.0.0-beta.32)
|
11
|
+
|
12
|
+
### Changes
|
13
|
+
|
14
|
+
- feat: add selectable feature to card ([PR #24486](https://github.com/microsoft/fluentui/pull/24486) by marcosvmmoura@gmail.com)
|
15
|
+
- Bump @fluentui/keyboard-keys to v9.0.1 ([PR #25615](https://github.com/microsoft/fluentui/pull/25615) by beachball)
|
16
|
+
- Bump @fluentui/react-tabster to v9.3.0 ([PR #25615](https://github.com/microsoft/fluentui/pull/25615) by beachball)
|
17
|
+
- Bump @fluentui/react-theme to v9.1.2 ([PR #25615](https://github.com/microsoft/fluentui/pull/25615) by beachball)
|
18
|
+
- Bump @fluentui/react-utilities to v9.2.1 ([PR #25615](https://github.com/microsoft/fluentui/pull/25615) by beachball)
|
19
|
+
- Bump @fluentui/react-conformance-griffel to v9.0.0-beta.18 ([PR #25615](https://github.com/microsoft/fluentui/pull/25615) by beachball)
|
20
|
+
- Bump @fluentui/react-button to v9.1.8 ([PR #25615](https://github.com/microsoft/fluentui/pull/25615) by beachball)
|
21
|
+
|
22
|
+
## [9.0.0-beta.31](https://github.com/microsoft/fluentui/tree/@fluentui/react-card_v9.0.0-beta.31)
|
23
|
+
|
24
|
+
Wed, 02 Nov 2022 11:57:49 GMT
|
25
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-card_v9.0.0-beta.30..@fluentui/react-card_v9.0.0-beta.31)
|
26
|
+
|
27
|
+
### Changes
|
28
|
+
|
29
|
+
- chore: Update Griffel to latest version ([PR #25412](https://github.com/microsoft/fluentui/pull/25412) by olfedias@microsoft.com)
|
30
|
+
- Bump @fluentui/react-utilities to v9.2.0 ([PR #25456](https://github.com/microsoft/fluentui/pull/25456) by beachball)
|
31
|
+
- Bump @fluentui/react-tabster to v9.2.1 ([PR #25456](https://github.com/microsoft/fluentui/pull/25456) by beachball)
|
32
|
+
- Bump @fluentui/react-conformance-griffel to v9.0.0-beta.17 ([PR #25456](https://github.com/microsoft/fluentui/pull/25456) by beachball)
|
33
|
+
- Bump @fluentui/react-text to v9.1.5 ([PR #25456](https://github.com/microsoft/fluentui/pull/25456) by beachball)
|
34
|
+
- Bump @fluentui/react-button to v9.1.7 ([PR #25456](https://github.com/microsoft/fluentui/pull/25456) by beachball)
|
35
|
+
|
7
36
|
## [9.0.0-beta.30](https://github.com/microsoft/fluentui/tree/@fluentui/react-card_v9.0.0-beta.30)
|
8
37
|
|
9
|
-
Tue, 25 Oct 2022 00:
|
38
|
+
Tue, 25 Oct 2022 00:35:40 GMT
|
10
39
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-card_v9.0.0-beta.29..@fluentui/react-card_v9.0.0-beta.30)
|
11
40
|
|
12
41
|
### Changes
|
package/dist/index.d.ts
CHANGED
@@ -110,6 +110,13 @@ export declare type CardHeaderSlots = {
|
|
110
110
|
*/
|
111
111
|
export declare type CardHeaderState = ComponentState<CardHeaderSlots>;
|
112
112
|
|
113
|
+
/**
|
114
|
+
* Data sent from the selection events on a selectable card.
|
115
|
+
*/
|
116
|
+
declare type CardOnSelectData = {
|
117
|
+
selected: boolean;
|
118
|
+
};
|
119
|
+
|
113
120
|
/**
|
114
121
|
* Component to render image previews of documents or articles in a Card component.
|
115
122
|
*/
|
@@ -148,6 +155,23 @@ export declare type CardPreviewState = ComponentState<CardPreviewSlots>;
|
|
148
155
|
* Card component props.
|
149
156
|
*/
|
150
157
|
export declare type CardProps = ComponentProps<CardSlots> & {
|
158
|
+
/**
|
159
|
+
* Sets the appearance of the card.
|
160
|
+
*
|
161
|
+
* `filled`
|
162
|
+
* The card will have a shadow, border and background color.
|
163
|
+
*
|
164
|
+
* `filled-alternative`
|
165
|
+
* This appearance is similar to `filled`, but the background color will be a little darker.
|
166
|
+
*
|
167
|
+
* `outline`
|
168
|
+
* This appearance is similar to `filled`, but the background color will be transparent and no shadow applied.
|
169
|
+
*
|
170
|
+
* `subtle`
|
171
|
+
* This appearance is similar to `filled-alternative`, but no border is applied.
|
172
|
+
*
|
173
|
+
* @default 'filled'
|
174
|
+
*/
|
151
175
|
appearance?: 'filled' | 'filled-alternative' | 'outline' | 'subtle';
|
152
176
|
/**
|
153
177
|
* Sets the focus behavior for the card. If `true`, the card will use the `noTab` focus behavior.
|
@@ -182,8 +206,29 @@ export declare type CardProps = ComponentProps<CardSlots> & {
|
|
182
206
|
* @default 'medium'
|
183
207
|
*/
|
184
208
|
size?: 'small' | 'medium' | 'large';
|
209
|
+
/**
|
210
|
+
* Defines the controlled selected state of the card.
|
211
|
+
*
|
212
|
+
* @default false
|
213
|
+
*/
|
214
|
+
selected?: boolean;
|
215
|
+
/**
|
216
|
+
* Defines whether the card is initially in a selected state or not when rendered.
|
217
|
+
*
|
218
|
+
* @default false
|
219
|
+
*/
|
220
|
+
defaultSelected?: boolean;
|
221
|
+
/**
|
222
|
+
* Callback to be called when the selected state value changes.
|
223
|
+
*/
|
224
|
+
onSelectionChange?: (event: CarOnSelectionChangeEvent, data: CardOnSelectData) => void;
|
185
225
|
};
|
186
226
|
|
227
|
+
/**
|
228
|
+
* Card refs to the root element slot.
|
229
|
+
*/
|
230
|
+
declare type CardRefElement = HTMLDivElement | HTMLButtonElement | HTMLAnchorElement;
|
231
|
+
|
187
232
|
/**
|
188
233
|
* Slots available in the Card component.
|
189
234
|
*/
|
@@ -191,13 +236,49 @@ export declare type CardSlots = {
|
|
191
236
|
/**
|
192
237
|
* Root element of the component.
|
193
238
|
*/
|
194
|
-
root: Slot<'div'>;
|
239
|
+
root: Slot<'div', 'a' | 'button'>;
|
240
|
+
/**
|
241
|
+
* Select element represents a checkbox.
|
242
|
+
*/
|
243
|
+
select?: Slot<'div', 'input'>;
|
195
244
|
};
|
196
245
|
|
197
246
|
/**
|
198
247
|
* State used in rendering Card.
|
199
248
|
*/
|
200
|
-
export declare type CardState = ComponentState<CardSlots> & Required<Pick<CardProps, 'appearance' | 'orientation' | 'size'
|
249
|
+
export declare type CardState = ComponentState<CardSlots> & Required<Pick<CardProps, 'appearance' | 'orientation' | 'size'> & {
|
250
|
+
/**
|
251
|
+
* Represents a card that contains interactive events (MouseEvents) or is a button/a tag.
|
252
|
+
*
|
253
|
+
* @default false
|
254
|
+
*/
|
255
|
+
interactive: boolean;
|
256
|
+
/**
|
257
|
+
* Represents a selectable card.
|
258
|
+
*
|
259
|
+
* @default false
|
260
|
+
*/
|
261
|
+
selectable: boolean;
|
262
|
+
/**
|
263
|
+
* Represents a selectable card that contains a slot for the select element.
|
264
|
+
*
|
265
|
+
* @default false
|
266
|
+
*/
|
267
|
+
hasSelectSlot: boolean;
|
268
|
+
/**
|
269
|
+
* Defines whether the card is currently selected.
|
270
|
+
*
|
271
|
+
* @default false
|
272
|
+
*/
|
273
|
+
selected: boolean;
|
274
|
+
}>;
|
275
|
+
|
276
|
+
/**
|
277
|
+
* Card selected event type
|
278
|
+
*
|
279
|
+
* This event is fired when a selectable card changes its selection state.
|
280
|
+
*/
|
281
|
+
export declare type CarOnSelectionChangeEvent = React_2.MouseEvent | React_2.KeyboardEvent | React_2.ChangeEvent;
|
201
282
|
|
202
283
|
/**
|
203
284
|
* Render the final JSX of Card.
|
@@ -226,9 +307,9 @@ export declare const renderCardPreview_unstable: (state: CardPreviewState) => JS
|
|
226
307
|
* before being passed to renderCard_unstable.
|
227
308
|
*
|
228
309
|
* @param props - props from this instance of Card
|
229
|
-
* @param ref - reference to root
|
310
|
+
* @param ref - reference to the root element of Card
|
230
311
|
*/
|
231
|
-
export declare const useCard_unstable: (props: CardProps, ref: React_2.Ref<
|
312
|
+
export declare const useCard_unstable: (props: CardProps, ref: React_2.Ref<CardRefElement>) => CardState;
|
232
313
|
|
233
314
|
/**
|
234
315
|
* Create the state required to render CardFooter.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/Card.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,gBAAT,QAAiC,WAAjC;AACA,SAAS,mBAAT,QAAoC,cAApC;AACA,SAAS,sBAAT,QAAuC,iBAAvC;AAIA;;AAEG;;AACH,OAAO,MAAM,IAAI,gBAAmC,KAAK,CAAC,UAAN,
|
1
|
+
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/Card.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,gBAAT,QAAiC,WAAjC;AACA,SAAS,mBAAT,QAAoC,cAApC;AACA,SAAS,sBAAT,QAAuC,iBAAvC;AAIA;;AAEG;;AACH,OAAO,MAAM,IAAI,gBAAmC,KAAK,CAAC,UAAN,CAAiC,CAAC,KAAD,EAAQ,GAAR,KAAe;EAClG,MAAM,KAAK,GAAG,gBAAgB,CAAC,KAAD,EAAQ,GAAR,CAA9B;EAEA,sBAAsB,CAAC,KAAD,CAAtB;EACA,OAAO,mBAAmB,CAAC,KAAD,CAA1B;AACD,CALmD,CAA7C;AAOP,IAAI,CAAC,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, CardRefElement } from './Card.types';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\n\n/**\n * A card provides scaffolding for hosting actions and content for a single topic.\n */\nexport const Card: ForwardRefComponent<CardProps> = React.forwardRef<CardRefElement>((props, ref) => {\n const state = useCard_unstable(props, ref);\n\n useCardStyles_unstable(state);\n return renderCard_unstable(state);\n});\n\nCard.displayName = 'Card';\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Card.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-card/src/components/Card/Card.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\n\n/**\n * Slots available in the Card component.\n */\nexport type CardSlots = {\n /**\n * Root element of the component.\n */\n root: Slot<'div'>;\n};\n\n/**\n * Card component props.\n */\nexport type CardProps = ComponentProps<CardSlots> & {\n appearance?: 'filled' | 'filled-alternative' | 'outline' | 'subtle';\n\n /**\n * Sets the focus behavior for the card. If `true`, the card will use the `noTab` focus behavior.\n *\n * `off`\n * The card will not focusable.\n *\n * `no-tab`\n * This behaviour traps the focus inside of the Card when pressing the Enter key and will only release focus when\n * pressing the Escape key.\n *\n * `tab-exit`\n * This behaviour traps the focus inside of the Card when pressing the Enter key but will release focus when pressing\n * the Tab key on the last inner element.\n *\n * `tab-only`\n * This behaviour will cycle through all elements inside of the Card when pressing the Tab key and then release focus\n * after the last inner element.\n *\n * @default 'off'\n */\n focusMode?: 'off' | 'no-tab' | 'tab-exit' | 'tab-only';\n\n /**\n * Defines the orientation of the card.\n *\n * @default 'vertical'\n */\n orientation?: 'horizontal' | 'vertical';\n\n /**\n * Controls the card's border radius and padding between inner elements.\n *\n * @default 'medium'\n */\n size?: 'small' | 'medium' | 'large';\n};\n\n/**\n * State used in rendering Card.\n */\nexport type CardState = ComponentState<CardSlots>
|
1
|
+
{"version":3,"file":"Card.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-card/src/components/Card/Card.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\n\n/**\n * Card refs to the root element slot.\n */\nexport type CardRefElement = HTMLDivElement | HTMLButtonElement | HTMLAnchorElement;\n\n/**\n * Card selected event type\n *\n * This event is fired when a selectable card changes its selection state.\n */\nexport type CarOnSelectionChangeEvent = React.MouseEvent | React.KeyboardEvent | React.ChangeEvent;\n\n/**\n * Data sent from the selection events on a selectable card.\n */\nexport type CardOnSelectData = {\n selected: boolean;\n};\n\n/**\n * Slots available in the Card component.\n */\nexport type CardSlots = {\n /**\n * Root element of the component.\n */\n root: Slot<'div', 'a' | 'button'>;\n\n /**\n * Select element represents a checkbox.\n */\n select?: Slot<'div', 'input'>;\n};\n\n/**\n * Card component props.\n */\nexport type CardProps = ComponentProps<CardSlots> & {\n /**\n * Sets the appearance of the card.\n *\n * `filled`\n * The card will have a shadow, border and background color.\n *\n * `filled-alternative`\n * This appearance is similar to `filled`, but the background color will be a little darker.\n *\n * `outline`\n * This appearance is similar to `filled`, but the background color will be transparent and no shadow applied.\n *\n * `subtle`\n * This appearance is similar to `filled-alternative`, but no border is applied.\n *\n * @default 'filled'\n */\n appearance?: 'filled' | 'filled-alternative' | 'outline' | 'subtle';\n\n /**\n * Sets the focus behavior for the card. If `true`, the card will use the `noTab` focus behavior.\n *\n * `off`\n * The card will not focusable.\n *\n * `no-tab`\n * This behaviour traps the focus inside of the Card when pressing the Enter key and will only release focus when\n * pressing the Escape key.\n *\n * `tab-exit`\n * This behaviour traps the focus inside of the Card when pressing the Enter key but will release focus when pressing\n * the Tab key on the last inner element.\n *\n * `tab-only`\n * This behaviour will cycle through all elements inside of the Card when pressing the Tab key and then release focus\n * after the last inner element.\n *\n * @default 'off'\n */\n focusMode?: 'off' | 'no-tab' | 'tab-exit' | 'tab-only';\n\n /**\n * Defines the orientation of the card.\n *\n * @default 'vertical'\n */\n orientation?: 'horizontal' | 'vertical';\n\n /**\n * Controls the card's border radius and padding between inner elements.\n *\n * @default 'medium'\n */\n size?: 'small' | 'medium' | 'large';\n\n /**\n * Defines the controlled selected state of the card.\n *\n * @default false\n */\n selected?: boolean;\n\n /**\n * Defines whether the card is initially in a selected state or not when rendered.\n *\n * @default false\n */\n defaultSelected?: boolean;\n\n /**\n * Callback to be called when the selected state value changes.\n */\n onSelectionChange?: (event: CarOnSelectionChangeEvent, data: CardOnSelectData) => void;\n};\n\n/**\n * State used in rendering Card.\n */\nexport type CardState = ComponentState<CardSlots> &\n Required<\n Pick<CardProps, 'appearance' | 'orientation' | 'size'> & {\n /**\n * Represents a card that contains interactive events (MouseEvents) or is a button/a tag.\n *\n * @default false\n */\n interactive: boolean;\n\n /**\n * Represents a selectable card.\n *\n * @default false\n */\n selectable: boolean;\n\n /**\n * Represents a selectable card that contains a slot for the select element.\n *\n * @default false\n */\n hasSelectSlot: boolean;\n\n /**\n * Defines whether the card is currently selected.\n *\n * @default false\n */\n selected: boolean;\n }\n >;\n"]}
|
@@ -10,6 +10,7 @@ export const renderCard_unstable = state => {
|
|
10
10
|
slotProps
|
11
11
|
} = getSlots(state);
|
12
12
|
return /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
|
13
|
-
}
|
13
|
+
}, slotProps.root.children, state.hasSelectSlot && slots.select ? /*#__PURE__*/React.createElement(slots.select, { ...slotProps.select
|
14
|
+
}) : null);
|
14
15
|
};
|
15
16
|
//# sourceMappingURL=renderCard.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/renderCard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAGA;;AAEG;;AACH,OAAO,MAAM,mBAAmB,GAAI,KAAD,IAAqB;EACtD,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,QAAQ,CAAY,KAAZ,CAArC;EAEA,
|
1
|
+
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/renderCard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAGA;;AAEG;;AACH,OAAO,MAAM,mBAAmB,GAAI,KAAD,IAAqB;EACtD,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,QAAQ,CAAY,KAAZ,CAArC;EAEA,oBACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;EAAf,CAAX,EACG,SAAS,CAAC,IAAV,CAAe,QADlB,EAEG,KAAK,CAAC,aAAN,IAAuB,KAAK,CAAC,MAA7B,gBAAsC,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,MAAP,EAAa,EAAA,GAAK,SAAS,CAAC;EAAf,CAAb,CAAtC,GAA+E,IAFlF,CADF;AAMD,CATM","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { CardSlots, CardState } from './Card.types';\n\n/**\n * Render the final JSX of Card.\n */\nexport const renderCard_unstable = (state: CardState) => {\n const { slots, slotProps } = getSlots<CardSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n {slotProps.root.children}\n {state.hasSelectSlot && slots.select ? <slots.select {...slotProps.select} /> : null}\n </slots.root>\n );\n};\n"],"sourceRoot":"../src/"}
|
@@ -1,5 +1,32 @@
|
|
1
|
+
import * as React from 'react';
|
1
2
|
import { getNativeElementProps } from '@fluentui/react-utilities';
|
2
3
|
import { useFocusableGroup } from '@fluentui/react-tabster';
|
4
|
+
import { useCardSelectable } from './useCardSelectable';
|
5
|
+
const focusMap = {
|
6
|
+
off: undefined,
|
7
|
+
'no-tab': 'limited-trap-focus',
|
8
|
+
'tab-exit': 'limited',
|
9
|
+
'tab-only': 'unlimited'
|
10
|
+
};
|
11
|
+
|
12
|
+
const useCardFocusAttributes = ({
|
13
|
+
focusMode = 'off'
|
14
|
+
}, {
|
15
|
+
interactive
|
16
|
+
}) => {
|
17
|
+
const internalFocusMode = interactive ? 'no-tab' : focusMode;
|
18
|
+
const groupperAttrs = useFocusableGroup({
|
19
|
+
tabBehavior: focusMap[internalFocusMode]
|
20
|
+
});
|
21
|
+
|
22
|
+
if (internalFocusMode === 'off') {
|
23
|
+
return null;
|
24
|
+
}
|
25
|
+
|
26
|
+
return { ...groupperAttrs,
|
27
|
+
tabIndex: 0
|
28
|
+
};
|
29
|
+
};
|
3
30
|
/**
|
4
31
|
* Create the state required to render Card.
|
5
32
|
*
|
@@ -7,42 +34,49 @@ import { useFocusableGroup } from '@fluentui/react-tabster';
|
|
7
34
|
* before being passed to renderCard_unstable.
|
8
35
|
*
|
9
36
|
* @param props - props from this instance of Card
|
10
|
-
* @param ref - reference to root
|
37
|
+
* @param ref - reference to the root element of Card
|
11
38
|
*/
|
12
39
|
|
40
|
+
|
13
41
|
export const useCard_unstable = (props, ref) => {
|
14
42
|
const {
|
15
43
|
appearance = 'filled',
|
16
|
-
focusMode = 'off',
|
17
44
|
orientation = 'vertical',
|
18
|
-
size = 'medium'
|
45
|
+
size = 'medium',
|
46
|
+
as = 'div'
|
19
47
|
} = props;
|
20
|
-
const
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
48
|
+
const cardRef = React.useRef(null);
|
49
|
+
const {
|
50
|
+
selectable,
|
51
|
+
hasSelectSlot,
|
52
|
+
selected,
|
53
|
+
selectableSlot,
|
54
|
+
selectableProps
|
55
|
+
} = useCardSelectable(props, cardRef);
|
56
|
+
const interactive = Boolean(selectable || ['a', 'button'].includes(as) || props.onClick || props.onDoubleClick || props.onMouseUp || props.onMouseDown || props.onPointerUp || props.onPointerDown || props.onTouchStart || props.onTouchEnd);
|
57
|
+
const focusAttributes = useCardFocusAttributes(props, {
|
58
|
+
interactive
|
28
59
|
});
|
29
|
-
const focusAttrs = focusMode !== 'off' ? {
|
30
|
-
tabIndex: 0,
|
31
|
-
...groupperAttrs
|
32
|
-
} : null;
|
33
60
|
return {
|
34
61
|
appearance,
|
35
62
|
orientation,
|
36
63
|
size,
|
64
|
+
interactive,
|
65
|
+
selectable,
|
66
|
+
hasSelectSlot,
|
67
|
+
selected,
|
37
68
|
components: {
|
38
|
-
root:
|
69
|
+
root: as,
|
70
|
+
select: 'div'
|
39
71
|
},
|
40
|
-
root: getNativeElementProps(
|
41
|
-
ref,
|
72
|
+
root: getNativeElementProps(as, {
|
73
|
+
ref: ref || cardRef,
|
42
74
|
role: 'group',
|
43
|
-
...
|
44
|
-
...props
|
45
|
-
|
75
|
+
...focusAttributes,
|
76
|
+
...props,
|
77
|
+
...selectableProps
|
78
|
+
}),
|
79
|
+
select: selectableSlot
|
46
80
|
};
|
47
81
|
};
|
48
82
|
//# sourceMappingURL=useCard.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/useCard.ts"],"names":[],"mappings":"AACA,SAAS,qBAAT,QAAsC,2BAAtC;
|
1
|
+
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/useCard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,qBAAT,QAAsC,2BAAtC;AACA,SAAS,iBAAT,QAAkC,yBAAlC;AAGA,SAAS,iBAAT,QAAkC,qBAAlC;AAEA,MAAM,QAAQ,GAAG;EACf,GAAG,EAAE,SADU;EAEf,UAAU,oBAFK;EAGf,YAAY,SAHG;EAIf,YAAY;AAJG,CAAjB;;AAWA,MAAM,sBAAsB,GAAG,CAAC;EAAE,SAAS,GAAG;AAAd,CAAD,EAAmC;EAAE;AAAF,CAAnC,KAAqF;EAClH,MAAM,iBAAiB,GAAG,WAAW,GAAG,QAAH,GAAc,SAAnD;EAEA,MAAM,aAAa,GAAG,iBAAiB,CAAC;IACtC,WAAW,EAAE,QAAQ,CAAC,iBAAD;EADiB,CAAD,CAAvC;;EAIA,IAAI,iBAAiB,KAAK,KAA1B,EAAiC;IAC/B,OAAO,IAAP;EACD;;EAED,OAAO,EACL,GAAG,aADE;IAEL,QAAQ,EAAE;EAFL,CAAP;AAID,CAfD;AAiBA;;;;;;;;AAQG;;;AACH,OAAO,MAAM,gBAAgB,GAAG,CAAC,KAAD,EAAmB,GAAnB,KAAgE;EAC9F,MAAM;IAAE,UAAU,GAAG,QAAf;IAAyB,WAAW,GAAG,UAAvC;IAAmD,IAAI,GAAG,QAA1D;IAAoE,EAAE,GAAG;EAAzE,IAAmF,KAAzF;EACA,MAAM,OAAO,GAAG,KAAK,CAAC,MAAN,CAA6B,IAA7B,CAAhB;EAEA,MAAM;IAAE,UAAF;IAAc,aAAd;IAA6B,QAA7B;IAAuC,cAAvC;IAAuD;EAAvD,IAA2E,iBAAiB,CAAC,KAAD,EAAQ,OAAR,CAAlG;EAEA,MAAM,WAAW,GAAG,OAAO,CACzB,UAAU,IACR,CAAC,GAAD,EAAM,QAAN,EAAgB,QAAhB,CAAyB,EAAzB,CADF,IAEE,KAAK,CAAC,OAFR,IAGE,KAAK,CAAC,aAHR,IAIE,KAAK,CAAC,SAJR,IAKE,KAAK,CAAC,WALR,IAME,KAAK,CAAC,WANR,IAOE,KAAK,CAAC,aAPR,IAQE,KAAK,CAAC,YARR,IASE,KAAK,CAAC,UAViB,CAA3B;EAaA,MAAM,eAAe,GAAG,sBAAsB,CAAC,KAAD,EAAQ;IAAE;EAAF,CAAR,CAA9C;EAEA,OAAO;IACL,UADK;IAEL,WAFK;IAGL,IAHK;IAIL,WAJK;IAKL,UALK;IAML,aANK;IAOL,QAPK;IASL,UAAU,EAAE;MACV,IAAI,EAAE,EADI;MAEV,MAAM,EAAE;IAFE,CATP;IAcL,IAAI,EAAE,qBAAqB,CAAC,EAAD,EAAK;MAC9B,GAAG,EAAE,GAAG,IAAI,OADkB;MAE9B,IAAI,EAAE,OAFwB;MAG9B,GAAG,eAH2B;MAI9B,GAAG,KAJ2B;MAK9B,GAAG;IAL2B,CAAL,CAdtB;IAsBL,MAAM,EAAE;EAtBH,CAAP;AAwBD,CA7CM","sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps } from '@fluentui/react-utilities';\nimport { useFocusableGroup } from '@fluentui/react-tabster';\n\nimport type { CardProps, CardRefElement, CardState } from './Card.types';\nimport { useCardSelectable } from './useCardSelectable';\n\nconst focusMap = {\n off: undefined,\n 'no-tab': 'limited-trap-focus',\n 'tab-exit': 'limited',\n 'tab-only': 'unlimited',\n} as const;\n\ntype UseCardFocusAttributesOptions = {\n interactive: boolean;\n};\n\nconst useCardFocusAttributes = ({ focusMode = 'off' }: CardProps, { interactive }: UseCardFocusAttributesOptions) => {\n const internalFocusMode = interactive ? 'no-tab' : focusMode;\n\n const groupperAttrs = useFocusableGroup({\n tabBehavior: focusMap[internalFocusMode],\n });\n\n if (internalFocusMode === 'off') {\n return null;\n }\n\n return {\n ...groupperAttrs,\n tabIndex: 0,\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<CardRefElement>): CardState => {\n const { appearance = 'filled', orientation = 'vertical', size = 'medium', as = 'div' } = props;\n const cardRef = React.useRef<CardRefElement>(null);\n\n const { selectable, hasSelectSlot, selected, selectableSlot, selectableProps } = useCardSelectable(props, cardRef);\n\n const interactive = Boolean(\n selectable ||\n ['a', 'button'].includes(as) ||\n props.onClick ||\n props.onDoubleClick ||\n props.onMouseUp ||\n props.onMouseDown ||\n props.onPointerUp ||\n props.onPointerDown ||\n props.onTouchStart ||\n props.onTouchEnd,\n );\n\n const focusAttributes = useCardFocusAttributes(props, { interactive });\n\n return {\n appearance,\n orientation,\n size,\n interactive,\n selectable,\n hasSelectSlot,\n selected,\n\n components: {\n root: as,\n select: 'div',\n },\n\n root: getNativeElementProps(as, {\n ref: ref || cardRef,\n role: 'group',\n ...focusAttributes,\n ...props,\n ...selectableProps,\n }),\n\n select: selectableSlot,\n };\n};\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { Enter, Space } from '@fluentui/keyboard-keys';
|
3
|
+
import { resolveShorthand } from '@fluentui/react-utilities';
|
4
|
+
import { useFocusFinders } from '@fluentui/react-tabster';
|
5
|
+
export const useCardSelectable = (props, cardRef) => {
|
6
|
+
const {
|
7
|
+
select,
|
8
|
+
selected,
|
9
|
+
defaultSelected,
|
10
|
+
onSelectionChange
|
11
|
+
} = props;
|
12
|
+
const {
|
13
|
+
findAllFocusable
|
14
|
+
} = useFocusFinders();
|
15
|
+
const selectableRef = React.useRef(null);
|
16
|
+
const isSelectable = [selected, defaultSelected, onSelectionChange, select].some(bool => typeof bool !== 'undefined');
|
17
|
+
const hasSelectSlot = Boolean(select);
|
18
|
+
const [isCardSelected, setIsCardSelected] = React.useState(false);
|
19
|
+
const shouldRestrictTriggerAction = React.useCallback(event => {
|
20
|
+
var _a;
|
21
|
+
|
22
|
+
if (!cardRef.current) {
|
23
|
+
return false;
|
24
|
+
}
|
25
|
+
|
26
|
+
const focusableElements = findAllFocusable(cardRef.current);
|
27
|
+
const target = event.target;
|
28
|
+
const isTargetInFocusableGroup = focusableElements.some(element => element.contains(target));
|
29
|
+
const isTargetInSelectableSlot = (_a = selectableRef === null || selectableRef === void 0 ? void 0 : selectableRef.current) === null || _a === void 0 ? void 0 : _a.contains(target);
|
30
|
+
return isTargetInFocusableGroup && !isTargetInSelectableSlot;
|
31
|
+
}, [cardRef, findAllFocusable]);
|
32
|
+
const onChangeHandler = React.useCallback(event => {
|
33
|
+
if (shouldRestrictTriggerAction(event)) {
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
|
37
|
+
const newCheckedValue = !isCardSelected;
|
38
|
+
setIsCardSelected(newCheckedValue);
|
39
|
+
|
40
|
+
if (onSelectionChange) {
|
41
|
+
onSelectionChange(event, {
|
42
|
+
selected: newCheckedValue
|
43
|
+
});
|
44
|
+
}
|
45
|
+
}, [onSelectionChange, isCardSelected, shouldRestrictTriggerAction]);
|
46
|
+
const onKeyDownHandler = React.useCallback(event => {
|
47
|
+
if ([Enter, Space].includes(event.key)) {
|
48
|
+
event.preventDefault();
|
49
|
+
onChangeHandler(event);
|
50
|
+
}
|
51
|
+
}, [onChangeHandler]);
|
52
|
+
const selectableProps = React.useMemo(() => {
|
53
|
+
if (!isSelectable) {
|
54
|
+
return null;
|
55
|
+
}
|
56
|
+
|
57
|
+
const selectableEvents = {
|
58
|
+
onClick: onChangeHandler,
|
59
|
+
onKeyDown: onKeyDownHandler
|
60
|
+
};
|
61
|
+
|
62
|
+
if (!hasSelectSlot) {
|
63
|
+
return { ...selectableEvents,
|
64
|
+
'aria-checked': isCardSelected
|
65
|
+
};
|
66
|
+
}
|
67
|
+
|
68
|
+
return selectableEvents;
|
69
|
+
}, [hasSelectSlot, isCardSelected, isSelectable, onChangeHandler, onKeyDownHandler]);
|
70
|
+
const selectableSlot = React.useMemo(() => {
|
71
|
+
if (!hasSelectSlot) {
|
72
|
+
return undefined;
|
73
|
+
}
|
74
|
+
|
75
|
+
return resolveShorthand(select, {
|
76
|
+
defaultProps: {
|
77
|
+
ref: selectableRef
|
78
|
+
}
|
79
|
+
});
|
80
|
+
}, [hasSelectSlot, select]);
|
81
|
+
React.useEffect(() => setIsCardSelected(Boolean(defaultSelected !== null && defaultSelected !== void 0 ? defaultSelected : selected)), [defaultSelected, selected, setIsCardSelected]);
|
82
|
+
return {
|
83
|
+
selected: isCardSelected,
|
84
|
+
selectable: isSelectable,
|
85
|
+
hasSelectSlot,
|
86
|
+
selectableProps,
|
87
|
+
selectableSlot
|
88
|
+
};
|
89
|
+
};
|
90
|
+
//# sourceMappingURL=useCardSelectable.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["packages/react-components/react-card/src/components/Card/useCardSelectable.ts"],"names":[],"mappings":"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","sourcesContent":["import * as React from 'react';\nimport { Enter, Space } from '@fluentui/keyboard-keys';\nimport { resolveShorthand } from '@fluentui/react-utilities';\nimport { useFocusFinders } from '@fluentui/react-tabster';\n\nimport type { CarOnSelectionChangeEvent, CardProps, CardRefElement } from './Card.types';\n\nexport const useCardSelectable = (props: CardProps, cardRef: React.RefObject<CardRefElement>) => {\n const { select, selected, defaultSelected, onSelectionChange } = props;\n\n const { findAllFocusable } = useFocusFinders();\n const selectableRef = React.useRef<HTMLDivElement>(null);\n\n const isSelectable = [selected, defaultSelected, onSelectionChange, select].some(bool => typeof bool !== 'undefined');\n const hasSelectSlot = Boolean(select);\n\n const [isCardSelected, setIsCardSelected] = React.useState(false);\n\n const shouldRestrictTriggerAction = React.useCallback(\n (event: CarOnSelectionChangeEvent) => {\n if (!cardRef.current) {\n return false;\n }\n\n const focusableElements = findAllFocusable(cardRef.current);\n const target = event.target as HTMLElement;\n const isTargetInFocusableGroup = focusableElements.some(element => element.contains(target));\n const isTargetInSelectableSlot = selectableRef?.current?.contains(target);\n\n return isTargetInFocusableGroup && !isTargetInSelectableSlot;\n },\n [cardRef, findAllFocusable],\n );\n const onChangeHandler = React.useCallback(\n (event: CarOnSelectionChangeEvent) => {\n if (shouldRestrictTriggerAction(event)) {\n return;\n }\n\n const newCheckedValue = !isCardSelected;\n\n setIsCardSelected(newCheckedValue);\n\n if (onSelectionChange) {\n onSelectionChange(event, {\n selected: newCheckedValue,\n });\n }\n },\n [onSelectionChange, isCardSelected, shouldRestrictTriggerAction],\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 selectableProps = React.useMemo(() => {\n if (!isSelectable) {\n return null;\n }\n\n const selectableEvents = {\n onClick: onChangeHandler,\n onKeyDown: onKeyDownHandler,\n };\n\n if (!hasSelectSlot) {\n return {\n ...selectableEvents,\n 'aria-checked': isCardSelected,\n };\n }\n\n return selectableEvents;\n }, [hasSelectSlot, isCardSelected, isSelectable, onChangeHandler, onKeyDownHandler]);\n\n const selectableSlot = React.useMemo(() => {\n if (!hasSelectSlot) {\n return undefined;\n }\n\n return resolveShorthand(select, {\n defaultProps: {\n ref: selectableRef,\n },\n });\n }, [hasSelectSlot, select]);\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 hasSelectSlot,\n selectableProps,\n selectableSlot,\n };\n};\n"],"sourceRoot":"../src/"}
|