@fluentui/react-rating 0.0.0-nightly-20240318-0408.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +187 -0
- package/LICENSE +15 -0
- package/README.md +38 -0
- package/dist/index.d.ts +291 -0
- package/lib/Rating.js +1 -0
- package/lib/Rating.js.map +1 -0
- package/lib/RatingDisplay.js +1 -0
- package/lib/RatingDisplay.js.map +1 -0
- package/lib/RatingItem.js +1 -0
- package/lib/RatingItem.js.map +1 -0
- package/lib/components/Rating/Rating.js +14 -0
- package/lib/components/Rating/Rating.js.map +1 -0
- package/lib/components/Rating/Rating.types.js +1 -0
- package/lib/components/Rating/Rating.types.js.map +1 -0
- package/lib/components/Rating/index.js +6 -0
- package/lib/components/Rating/index.js.map +1 -0
- package/lib/components/Rating/renderRating.js +12 -0
- package/lib/components/Rating/renderRating.js.map +1 -0
- package/lib/components/Rating/useRating.js +82 -0
- package/lib/components/Rating/useRating.js.map +1 -0
- package/lib/components/Rating/useRatingContextValues.js +29 -0
- package/lib/components/Rating/useRatingContextValues.js.map +1 -0
- package/lib/components/Rating/useRatingStyles.styles.js +17 -0
- package/lib/components/Rating/useRatingStyles.styles.js.map +1 -0
- package/lib/components/RatingDisplay/RatingDisplay.js +15 -0
- package/lib/components/RatingDisplay/RatingDisplay.js.map +1 -0
- package/lib/components/RatingDisplay/RatingDisplay.types.js +1 -0
- package/lib/components/RatingDisplay/RatingDisplay.types.js.map +1 -0
- package/lib/components/RatingDisplay/index.js +6 -0
- package/lib/components/RatingDisplay/index.js.map +1 -0
- package/lib/components/RatingDisplay/renderRatingDisplay.js +18 -0
- package/lib/components/RatingDisplay/renderRatingDisplay.js.map +1 -0
- package/lib/components/RatingDisplay/useRatingDisplay.js +79 -0
- package/lib/components/RatingDisplay/useRatingDisplay.js.map +1 -0
- package/lib/components/RatingDisplay/useRatingDisplayContextValues.js +23 -0
- package/lib/components/RatingDisplay/useRatingDisplayContextValues.js.map +1 -0
- package/lib/components/RatingDisplay/useRatingDisplayStyles.styles.js +50 -0
- package/lib/components/RatingDisplay/useRatingDisplayStyles.styles.js.map +1 -0
- package/lib/components/RatingItem/RatingItem.js +12 -0
- package/lib/components/RatingItem/RatingItem.js.map +1 -0
- package/lib/components/RatingItem/RatingItem.types.js +1 -0
- package/lib/components/RatingItem/RatingItem.types.js.map +1 -0
- package/lib/components/RatingItem/index.js +5 -0
- package/lib/components/RatingItem/index.js.map +1 -0
- package/lib/components/RatingItem/renderRatingItem.js +15 -0
- package/lib/components/RatingItem/renderRatingItem.js.map +1 -0
- package/lib/components/RatingItem/useRatingItem.js +111 -0
- package/lib/components/RatingItem/useRatingItem.js.map +1 -0
- package/lib/components/RatingItem/useRatingItemStyles.styles.js +163 -0
- package/lib/components/RatingItem/useRatingItemStyles.styles.js.map +1 -0
- package/lib/contexts/RatingItemContext.js +16 -0
- package/lib/contexts/RatingItemContext.js.map +1 -0
- package/lib/contexts/index.js +1 -0
- package/lib/contexts/index.js.map +1 -0
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -0
- package/lib-commonjs/Rating.js +6 -0
- package/lib-commonjs/Rating.js.map +1 -0
- package/lib-commonjs/RatingDisplay.js +6 -0
- package/lib-commonjs/RatingDisplay.js.map +1 -0
- package/lib-commonjs/RatingItem.js +6 -0
- package/lib-commonjs/RatingItem.js.map +1 -0
- package/lib-commonjs/components/Rating/Rating.js +23 -0
- package/lib-commonjs/components/Rating/Rating.js.map +1 -0
- package/lib-commonjs/components/Rating/Rating.types.js +6 -0
- package/lib-commonjs/components/Rating/Rating.types.js.map +1 -0
- package/lib-commonjs/components/Rating/index.js +11 -0
- package/lib-commonjs/components/Rating/index.js.map +1 -0
- package/lib-commonjs/components/Rating/renderRating.js +20 -0
- package/lib-commonjs/components/Rating/renderRating.js.map +1 -0
- package/lib-commonjs/components/Rating/useRating.js +85 -0
- package/lib-commonjs/components/Rating/useRating.js.map +1 -0
- package/lib-commonjs/components/Rating/useRatingContextValues.js +40 -0
- package/lib-commonjs/components/Rating/useRatingContextValues.js.map +1 -0
- package/lib-commonjs/components/Rating/useRatingStyles.styles.js +32 -0
- package/lib-commonjs/components/Rating/useRatingStyles.styles.js.map +1 -0
- package/lib-commonjs/components/RatingDisplay/RatingDisplay.js +23 -0
- package/lib-commonjs/components/RatingDisplay/RatingDisplay.js.map +1 -0
- package/lib-commonjs/components/RatingDisplay/RatingDisplay.types.js +6 -0
- package/lib-commonjs/components/RatingDisplay/RatingDisplay.types.js.map +1 -0
- package/lib-commonjs/components/RatingDisplay/index.js +11 -0
- package/lib-commonjs/components/RatingDisplay/index.js.map +1 -0
- package/lib-commonjs/components/RatingDisplay/renderRatingDisplay.js +26 -0
- package/lib-commonjs/components/RatingDisplay/renderRatingDisplay.js.map +1 -0
- package/lib-commonjs/components/RatingDisplay/useRatingDisplay.js +82 -0
- package/lib-commonjs/components/RatingDisplay/useRatingDisplay.js.map +1 -0
- package/lib-commonjs/components/RatingDisplay/useRatingDisplayContextValues.js +34 -0
- package/lib-commonjs/components/RatingDisplay/useRatingDisplayContextValues.js.map +1 -0
- package/lib-commonjs/components/RatingDisplay/useRatingDisplayStyles.styles.js +72 -0
- package/lib-commonjs/components/RatingDisplay/useRatingDisplayStyles.styles.js.map +1 -0
- package/lib-commonjs/components/RatingItem/RatingItem.js +21 -0
- package/lib-commonjs/components/RatingItem/RatingItem.js.map +1 -0
- package/lib-commonjs/components/RatingItem/RatingItem.types.js +4 -0
- package/lib-commonjs/components/RatingItem/RatingItem.types.js.map +1 -0
- package/lib-commonjs/components/RatingItem/index.js +10 -0
- package/lib-commonjs/components/RatingItem/index.js.map +1 -0
- package/lib-commonjs/components/RatingItem/renderRatingItem.js +23 -0
- package/lib-commonjs/components/RatingItem/renderRatingItem.js.map +1 -0
- package/lib-commonjs/components/RatingItem/useRatingItem.js +114 -0
- package/lib-commonjs/components/RatingItem/useRatingItem.js.map +1 -0
- package/lib-commonjs/components/RatingItem/useRatingItemStyles.styles.js +323 -0
- package/lib-commonjs/components/RatingItem/useRatingItemStyles.styles.js.map +1 -0
- package/lib-commonjs/contexts/RatingItemContext.js +34 -0
- package/lib-commonjs/contexts/RatingItemContext.js.map +1 -0
- package/lib-commonjs/contexts/index.js +6 -0
- package/lib-commonjs/contexts/index.js.map +1 -0
- package/lib-commonjs/index.js +73 -0
- package/lib-commonjs/index.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["renderRatingDisplay.js"],"sourcesContent":[" import { jsx as _jsx, jsxs as _jsxs } from \"@fluentui/react-jsx-runtime/jsx-runtime\";\nimport { assertSlots } from '@fluentui/react-utilities';\nimport { RatingItemProvider } from '../../contexts/RatingItemContext';\n/**\n * Render the final JSX of RatingDisplay\n */ export const renderRatingDisplay_unstable = (state, contextValues)=>{\n assertSlots(state);\n return /*#__PURE__*/ _jsx(RatingItemProvider, {\n value: contextValues.ratingItem,\n children: /*#__PURE__*/ _jsxs(state.root, {\n children: [\n state.root.children,\n state.valueText && /*#__PURE__*/ _jsx(state.valueText, {}),\n state.countText && /*#__PURE__*/ _jsx(state.countText, {})\n ]\n })\n });\n};\n"],"names":["renderRatingDisplay_unstable","state","contextValues","assertSlots","_jsx","RatingItemProvider","value","ratingItem","children","_jsxs","root","valueText","countText"],"mappings":";;;;+BAKiBA;;;eAAAA;;;4BAL4B;gCACjB;mCACO;AAGxB,MAAMA,+BAA+B,CAACC,OAAOC;IACpDC,IAAAA,2BAAW,EAACF;IACZ,OAAO,WAAW,GAAGG,IAAAA,eAAI,EAACC,qCAAkB,EAAE;QAC1CC,OAAOJ,cAAcK,UAAU;QAC/BC,UAAU,WAAW,GAAGC,IAAAA,gBAAK,EAACR,MAAMS,IAAI,EAAE;YACtCF,UAAU;gBACNP,MAAMS,IAAI,CAACF,QAAQ;gBACnBP,MAAMU,SAAS,IAAI,WAAW,GAAGP,IAAAA,eAAI,EAACH,MAAMU,SAAS,EAAE,CAAC;gBACxDV,MAAMW,SAAS,IAAI,WAAW,GAAGR,IAAAA,eAAI,EAACH,MAAMW,SAAS,EAAE,CAAC;aAC3D;QACL;IACJ;AACJ"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useRatingDisplay_unstable", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useRatingDisplay_unstable;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
13
|
+
const _reactutilities = require("@fluentui/react-utilities");
|
|
14
|
+
const _reacticons = require("@fluentui/react-icons");
|
|
15
|
+
const _RatingItem = require("../RatingItem/RatingItem");
|
|
16
|
+
const useRatingDisplay_unstable = (props, ref)=>{
|
|
17
|
+
const { color = 'neutral', count, compact = false, icon = _reacticons.StarFilled, max = 5, size = 'medium', value } = props;
|
|
18
|
+
const valueTextId = (0, _reactutilities.useId)('rating-value-');
|
|
19
|
+
const countTextId = (0, _reactutilities.useId)('rating-count-');
|
|
20
|
+
// Generate the child RatingItems and memoize them to prevent unnecessary re-rendering
|
|
21
|
+
const rootChildren = _react.useMemo(()=>{
|
|
22
|
+
return compact ? /*#__PURE__*/ _react.createElement(_RatingItem.RatingItem, {
|
|
23
|
+
value: 1,
|
|
24
|
+
key: 1,
|
|
25
|
+
"aria-hidden": true
|
|
26
|
+
}) : Array.from(Array(max), (_, i)=>/*#__PURE__*/ _react.createElement(_RatingItem.RatingItem, {
|
|
27
|
+
value: i + 1,
|
|
28
|
+
key: i + 1,
|
|
29
|
+
"aria-hidden": true
|
|
30
|
+
}));
|
|
31
|
+
}, [
|
|
32
|
+
compact,
|
|
33
|
+
max
|
|
34
|
+
]);
|
|
35
|
+
const state = {
|
|
36
|
+
color,
|
|
37
|
+
compact,
|
|
38
|
+
icon,
|
|
39
|
+
max,
|
|
40
|
+
size,
|
|
41
|
+
value,
|
|
42
|
+
components: {
|
|
43
|
+
root: 'div',
|
|
44
|
+
valueText: 'span',
|
|
45
|
+
countText: 'span'
|
|
46
|
+
},
|
|
47
|
+
root: _reactutilities.slot.always((0, _reactutilities.getIntrinsicElementProps)('div', {
|
|
48
|
+
ref,
|
|
49
|
+
children: rootChildren,
|
|
50
|
+
role: 'img',
|
|
51
|
+
...props
|
|
52
|
+
}), {
|
|
53
|
+
elementType: 'div'
|
|
54
|
+
}),
|
|
55
|
+
valueText: _reactutilities.slot.optional(props.valueText, {
|
|
56
|
+
renderByDefault: value !== undefined,
|
|
57
|
+
defaultProps: {
|
|
58
|
+
children: value,
|
|
59
|
+
id: valueTextId,
|
|
60
|
+
'aria-hidden': true
|
|
61
|
+
},
|
|
62
|
+
elementType: 'span'
|
|
63
|
+
}),
|
|
64
|
+
countText: _reactutilities.slot.optional(props.countText, {
|
|
65
|
+
renderByDefault: count !== undefined,
|
|
66
|
+
defaultProps: {
|
|
67
|
+
children: count === null || count === void 0 ? void 0 : count.toLocaleString(),
|
|
68
|
+
id: countTextId,
|
|
69
|
+
'aria-hidden': true
|
|
70
|
+
},
|
|
71
|
+
elementType: 'span'
|
|
72
|
+
})
|
|
73
|
+
};
|
|
74
|
+
if (!state.root['aria-label'] && !state.root['aria-labelledby']) {
|
|
75
|
+
var _state_valueText, _state_countText;
|
|
76
|
+
state.root['aria-labelledby'] = [
|
|
77
|
+
(_state_valueText = state.valueText) === null || _state_valueText === void 0 ? void 0 : _state_valueText.id,
|
|
78
|
+
(_state_countText = state.countText) === null || _state_countText === void 0 ? void 0 : _state_countText.id
|
|
79
|
+
].filter(Boolean).join(' ');
|
|
80
|
+
}
|
|
81
|
+
return state;
|
|
82
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useRatingDisplay.js"],"sourcesContent":["import * as React from 'react';\nimport { getIntrinsicElementProps, slot, useId } from '@fluentui/react-utilities';\nimport { StarFilled } from '@fluentui/react-icons';\nimport { RatingItem } from '../RatingItem/RatingItem';\n/**\n * Create the state required to render RatingDisplay.\n *\n * The returned state can be modified with hooks such as useRatingDisplayStyles_unstable,\n * before being passed to renderRatingDisplay_unstable.\n *\n * @param props - props from this instance of RatingDisplay\n * @param ref - reference to root HTMLDivElement of RatingDisplay\n */ export const useRatingDisplay_unstable = (props, ref)=>{\n const { color = 'neutral', count, compact = false, icon = StarFilled, max = 5, size = 'medium', value } = props;\n const valueTextId = useId('rating-value-');\n const countTextId = useId('rating-count-');\n // Generate the child RatingItems and memoize them to prevent unnecessary re-rendering\n const rootChildren = React.useMemo(()=>{\n return compact ? /*#__PURE__*/ React.createElement(RatingItem, {\n value: 1,\n key: 1,\n \"aria-hidden\": true\n }) : Array.from(Array(max), (_, i)=>/*#__PURE__*/ React.createElement(RatingItem, {\n value: i + 1,\n key: i + 1,\n \"aria-hidden\": true\n }));\n }, [\n compact,\n max\n ]);\n const state = {\n color,\n compact,\n icon,\n max,\n size,\n value,\n components: {\n root: 'div',\n valueText: 'span',\n countText: 'span'\n },\n root: slot.always(getIntrinsicElementProps('div', {\n ref,\n children: rootChildren,\n role: 'img',\n ...props\n }), {\n elementType: 'div'\n }),\n valueText: slot.optional(props.valueText, {\n renderByDefault: value !== undefined,\n defaultProps: {\n children: value,\n id: valueTextId,\n 'aria-hidden': true\n },\n elementType: 'span'\n }),\n countText: slot.optional(props.countText, {\n renderByDefault: count !== undefined,\n defaultProps: {\n children: count === null || count === void 0 ? void 0 : count.toLocaleString(),\n id: countTextId,\n 'aria-hidden': true\n },\n elementType: 'span'\n })\n };\n if (!state.root['aria-label'] && !state.root['aria-labelledby']) {\n var _state_valueText, _state_countText;\n state.root['aria-labelledby'] = [\n (_state_valueText = state.valueText) === null || _state_valueText === void 0 ? void 0 : _state_valueText.id,\n (_state_countText = state.countText) === null || _state_countText === void 0 ? void 0 : _state_countText.id\n ].filter(Boolean).join(' ');\n }\n return state;\n};\n"],"names":["useRatingDisplay_unstable","props","ref","color","count","compact","icon","StarFilled","max","size","value","valueTextId","useId","countTextId","rootChildren","React","useMemo","createElement","RatingItem","key","Array","from","_","i","state","components","root","valueText","countText","slot","always","getIntrinsicElementProps","children","role","elementType","optional","renderByDefault","undefined","defaultProps","id","toLocaleString","_state_valueText","_state_countText","filter","Boolean","join"],"mappings":";;;;+BAYiBA;;;eAAAA;;;;iEAZM;gCAC+B;4BAC3B;4BACA;AAShB,MAAMA,4BAA4B,CAACC,OAAOC;IACjD,MAAM,EAAEC,QAAQ,SAAS,EAAEC,KAAK,EAAEC,UAAU,KAAK,EAAEC,OAAOC,sBAAU,EAAEC,MAAM,CAAC,EAAEC,OAAO,QAAQ,EAAEC,KAAK,EAAE,GAAGT;IAC1G,MAAMU,cAAcC,IAAAA,qBAAK,EAAC;IAC1B,MAAMC,cAAcD,IAAAA,qBAAK,EAAC;IAC1B,sFAAsF;IACtF,MAAME,eAAeC,OAAMC,OAAO,CAAC;QAC/B,OAAOX,UAAU,WAAW,GAAGU,OAAME,aAAa,CAACC,sBAAU,EAAE;YAC3DR,OAAO;YACPS,KAAK;YACL,eAAe;QACnB,KAAKC,MAAMC,IAAI,CAACD,MAAMZ,MAAM,CAACc,GAAGC,IAAI,WAAW,GAAGR,OAAME,aAAa,CAACC,sBAAU,EAAE;gBAC1ER,OAAOa,IAAI;gBACXJ,KAAKI,IAAI;gBACT,eAAe;YACnB;IACR,GAAG;QACClB;QACAG;KACH;IACD,MAAMgB,QAAQ;QACVrB;QACAE;QACAC;QACAE;QACAC;QACAC;QACAe,YAAY;YACRC,MAAM;YACNC,WAAW;YACXC,WAAW;QACf;QACAF,MAAMG,oBAAI,CAACC,MAAM,CAACC,IAAAA,wCAAwB,EAAC,OAAO;YAC9C7B;YACA8B,UAAUlB;YACVmB,MAAM;YACN,GAAGhC,KAAK;QACZ,IAAI;YACAiC,aAAa;QACjB;QACAP,WAAWE,oBAAI,CAACM,QAAQ,CAAClC,MAAM0B,SAAS,EAAE;YACtCS,iBAAiB1B,UAAU2B;YAC3BC,cAAc;gBACVN,UAAUtB;gBACV6B,IAAI5B;gBACJ,eAAe;YACnB;YACAuB,aAAa;QACjB;QACAN,WAAWC,oBAAI,CAACM,QAAQ,CAAClC,MAAM2B,SAAS,EAAE;YACtCQ,iBAAiBhC,UAAUiC;YAC3BC,cAAc;gBACVN,UAAU5B,UAAU,QAAQA,UAAU,KAAK,IAAI,KAAK,IAAIA,MAAMoC,cAAc;gBAC5ED,IAAI1B;gBACJ,eAAe;YACnB;YACAqB,aAAa;QACjB;IACJ;IACA,IAAI,CAACV,MAAME,IAAI,CAAC,aAAa,IAAI,CAACF,MAAME,IAAI,CAAC,kBAAkB,EAAE;QAC7D,IAAIe,kBAAkBC;QACtBlB,MAAME,IAAI,CAAC,kBAAkB,GAAG;YAC3Be,CAAAA,mBAAmBjB,MAAMG,SAAS,AAAD,MAAO,QAAQc,qBAAqB,KAAK,IAAI,KAAK,IAAIA,iBAAiBF,EAAE;YAC1GG,CAAAA,mBAAmBlB,MAAMI,SAAS,AAAD,MAAO,QAAQc,qBAAqB,KAAK,IAAI,KAAK,IAAIA,iBAAiBH,EAAE;SAC9G,CAACI,MAAM,CAACC,SAASC,IAAI,CAAC;IAC3B;IACA,OAAOrB;AACX"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useRatingDisplayContextValues", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useRatingDisplayContextValues;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
13
|
+
const useRatingDisplayContextValues = (state)=>{
|
|
14
|
+
const { color, compact, icon, size, value } = state;
|
|
15
|
+
const ratingItem = _react.useMemo(()=>({
|
|
16
|
+
color,
|
|
17
|
+
compact,
|
|
18
|
+
iconFilled: icon,
|
|
19
|
+
iconOutline: icon,
|
|
20
|
+
interactive: false,
|
|
21
|
+
step: 0.5,
|
|
22
|
+
size,
|
|
23
|
+
value
|
|
24
|
+
}), [
|
|
25
|
+
color,
|
|
26
|
+
compact,
|
|
27
|
+
icon,
|
|
28
|
+
size,
|
|
29
|
+
value
|
|
30
|
+
]);
|
|
31
|
+
return {
|
|
32
|
+
ratingItem
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useRatingDisplayContextValues.js"],"sourcesContent":["import * as React from 'react';\nexport const useRatingDisplayContextValues = (state)=>{\n const { color, compact, icon, size, value } = state;\n const ratingItem = React.useMemo(()=>({\n color,\n compact,\n iconFilled: icon,\n iconOutline: icon,\n interactive: false,\n step: 0.5,\n size,\n value\n }), [\n color,\n compact,\n icon,\n size,\n value\n ]);\n return {\n ratingItem\n };\n};\n"],"names":["useRatingDisplayContextValues","state","color","compact","icon","size","value","ratingItem","React","useMemo","iconFilled","iconOutline","interactive","step"],"mappings":";;;;+BACaA;;;eAAAA;;;;iEADU;AAChB,MAAMA,gCAAgC,CAACC;IAC1C,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAEC,IAAI,EAAEC,IAAI,EAAEC,KAAK,EAAE,GAAGL;IAC9C,MAAMM,aAAaC,OAAMC,OAAO,CAAC,IAAK,CAAA;YAC9BP;YACAC;YACAO,YAAYN;YACZO,aAAaP;YACbQ,aAAa;YACbC,MAAM;YACNR;YACAC;QACJ,CAAA,GAAI;QACJJ;QACAC;QACAC;QACAC;QACAC;KACH;IACD,OAAO;QACHC;IACJ;AACJ"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
ratingDisplayClassNames: function() {
|
|
13
|
+
return ratingDisplayClassNames;
|
|
14
|
+
},
|
|
15
|
+
useRatingDisplayStyles_unstable: function() {
|
|
16
|
+
return useRatingDisplayStyles_unstable;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _react = require("@griffel/react");
|
|
20
|
+
const ratingDisplayClassNames = {
|
|
21
|
+
root: 'fui-RatingDisplay',
|
|
22
|
+
valueText: 'fui-RatingDisplay__valueText',
|
|
23
|
+
countText: 'fui-RatingDisplay__countText'
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Styles for the root slot
|
|
27
|
+
*/ const useRootClassName = /*#__PURE__*/ (0, _react.__resetStyles)("rxxdqwu", null, [
|
|
28
|
+
".rxxdqwu{display:flex;flex-wrap:wrap;align-items:center;}"
|
|
29
|
+
]);
|
|
30
|
+
const useLabelClassName = /*#__PURE__*/ (0, _react.__resetStyles)("r1okbz36", "rzju99d", [
|
|
31
|
+
".r1okbz36{color:var(--colorNeutralForeground1);margin-left:var(--spacingHorizontalXXS);font-family:var(--fontFamilyBase);font-size:var(--fontSizeBase200);font-weight:var(--fontWeightRegular);line-height:var(--lineHeightBase200);}",
|
|
32
|
+
".rzju99d{color:var(--colorNeutralForeground1);margin-right:var(--spacingHorizontalXXS);font-family:var(--fontFamilyBase);font-size:var(--fontSizeBase200);font-weight:var(--fontWeightRegular);line-height:var(--lineHeightBase200);}"
|
|
33
|
+
]);
|
|
34
|
+
const useLabelStyles = /*#__PURE__*/ (0, _react.__styles)({
|
|
35
|
+
large: {
|
|
36
|
+
Be2twd7: "fkhj508",
|
|
37
|
+
Bg96gwp: "f1i3iumi"
|
|
38
|
+
},
|
|
39
|
+
extraLarge: {
|
|
40
|
+
Be2twd7: "fod5ikn",
|
|
41
|
+
Bg96gwp: "faaz57k"
|
|
42
|
+
},
|
|
43
|
+
strong: {
|
|
44
|
+
Bhrd7zp: "fl43uef"
|
|
45
|
+
},
|
|
46
|
+
divider: {
|
|
47
|
+
Ftih45: "f169p45e"
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
d: [
|
|
51
|
+
".fkhj508{font-size:var(--fontSizeBase300);}",
|
|
52
|
+
".f1i3iumi{line-height:var(--lineHeightBase300);}",
|
|
53
|
+
".fod5ikn{font-size:var(--fontSizeBase400);}",
|
|
54
|
+
".faaz57k{line-height:var(--lineHeightBase400);}",
|
|
55
|
+
".fl43uef{font-weight:var(--fontWeightSemibold);}",
|
|
56
|
+
".f169p45e::before{content:\"\xB7 \";}"
|
|
57
|
+
]
|
|
58
|
+
});
|
|
59
|
+
const useRatingDisplayStyles_unstable = (state)=>{
|
|
60
|
+
const { size } = state;
|
|
61
|
+
const rootClassName = useRootClassName();
|
|
62
|
+
state.root.className = (0, _react.mergeClasses)(ratingDisplayClassNames.root, rootClassName, state.root.className);
|
|
63
|
+
const labelClassName = useLabelClassName();
|
|
64
|
+
const labelStyles = useLabelStyles();
|
|
65
|
+
if (state.valueText) {
|
|
66
|
+
state.valueText.className = (0, _react.mergeClasses)(ratingDisplayClassNames.valueText, labelClassName, labelStyles.strong, size === 'large' && labelStyles.large, size === 'extra-large' && labelStyles.extraLarge, state.valueText.className);
|
|
67
|
+
}
|
|
68
|
+
if (state.countText) {
|
|
69
|
+
state.countText.className = (0, _react.mergeClasses)(ratingDisplayClassNames.countText, labelClassName, size === 'large' && labelStyles.large, size === 'extra-large' && labelStyles.extraLarge, state.valueText && labelStyles.divider, state.countText.className);
|
|
70
|
+
}
|
|
71
|
+
return state;
|
|
72
|
+
}; //# sourceMappingURL=useRatingDisplayStyles.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useRatingDisplayStyles.styles.js"],"sourcesContent":["import { __resetStyles, __styles, mergeClasses } from '@griffel/react';\nimport { tokens, typographyStyles } from '@fluentui/react-theme';\nexport const ratingDisplayClassNames = {\n root: 'fui-RatingDisplay',\n valueText: 'fui-RatingDisplay__valueText',\n countText: 'fui-RatingDisplay__countText'\n};\n/**\n * Styles for the root slot\n */\nconst useRootClassName = /*#__PURE__*/__resetStyles(\"rxxdqwu\", null, [\".rxxdqwu{display:flex;flex-wrap:wrap;align-items:center;}\"]);\nconst useLabelClassName = /*#__PURE__*/__resetStyles(\"r1okbz36\", \"rzju99d\", [\".r1okbz36{color:var(--colorNeutralForeground1);margin-left:var(--spacingHorizontalXXS);font-family:var(--fontFamilyBase);font-size:var(--fontSizeBase200);font-weight:var(--fontWeightRegular);line-height:var(--lineHeightBase200);}\", \".rzju99d{color:var(--colorNeutralForeground1);margin-right:var(--spacingHorizontalXXS);font-family:var(--fontFamilyBase);font-size:var(--fontSizeBase200);font-weight:var(--fontWeightRegular);line-height:var(--lineHeightBase200);}\"]);\nconst useLabelStyles = /*#__PURE__*/__styles({\n large: {\n Be2twd7: \"fkhj508\",\n Bg96gwp: \"f1i3iumi\"\n },\n extraLarge: {\n Be2twd7: \"fod5ikn\",\n Bg96gwp: \"faaz57k\"\n },\n strong: {\n Bhrd7zp: \"fl43uef\"\n },\n divider: {\n Ftih45: \"f169p45e\"\n }\n}, {\n d: [\".fkhj508{font-size:var(--fontSizeBase300);}\", \".f1i3iumi{line-height:var(--lineHeightBase300);}\", \".fod5ikn{font-size:var(--fontSizeBase400);}\", \".faaz57k{line-height:var(--lineHeightBase400);}\", \".fl43uef{font-weight:var(--fontWeightSemibold);}\", \".f169p45e::before{content:\\\"\\xB7 \\\";}\"]\n});\n/**\n * Apply styling to the RatingDisplay slots based on the state\n */\nexport const useRatingDisplayStyles_unstable = state => {\n const {\n size\n } = state;\n const rootClassName = useRootClassName();\n state.root.className = mergeClasses(ratingDisplayClassNames.root, rootClassName, state.root.className);\n const labelClassName = useLabelClassName();\n const labelStyles = useLabelStyles();\n if (state.valueText) {\n state.valueText.className = mergeClasses(ratingDisplayClassNames.valueText, labelClassName, labelStyles.strong, size === 'large' && labelStyles.large, size === 'extra-large' && labelStyles.extraLarge, state.valueText.className);\n }\n if (state.countText) {\n state.countText.className = mergeClasses(ratingDisplayClassNames.countText, labelClassName, size === 'large' && labelStyles.large, size === 'extra-large' && labelStyles.extraLarge, state.valueText && labelStyles.divider, state.countText.className);\n }\n return state;\n};\n//# sourceMappingURL=useRatingDisplayStyles.styles.js.map"],"names":["ratingDisplayClassNames","useRatingDisplayStyles_unstable","root","valueText","countText","useRootClassName","__resetStyles","useLabelClassName","useLabelStyles","__styles","large","Be2twd7","Bg96gwp","extraLarge","strong","Bhrd7zp","divider","Ftih45","d","state","size","rootClassName","className","mergeClasses","labelClassName","labelStyles"],"mappings":";;;;;;;;;;;IAEaA,uBAAuB;eAAvBA;;IA+BAC,+BAA+B;eAA/BA;;;uBAjCyC;AAE/C,MAAMD,0BAA0B;IACrCE,MAAM;IACNC,WAAW;IACXC,WAAW;AACb;AACA;;CAEC,GACD,MAAMC,mBAAmB,WAAW,GAAEC,IAAAA,oBAAa,EAAC,WAAW,MAAM;IAAC;CAA4D;AAClI,MAAMC,oBAAoB,WAAW,GAAED,IAAAA,oBAAa,EAAC,YAAY,WAAW;IAAC;IAAyO;CAAwO;AAC9hB,MAAME,iBAAiB,WAAW,GAAEC,IAAAA,eAAQ,EAAC;IAC3CC,OAAO;QACLC,SAAS;QACTC,SAAS;IACX;IACAC,YAAY;QACVF,SAAS;QACTC,SAAS;IACX;IACAE,QAAQ;QACNC,SAAS;IACX;IACAC,SAAS;QACPC,QAAQ;IACV;AACF,GAAG;IACDC,GAAG;QAAC;QAA+C;QAAoD;QAA+C;QAAmD;QAAoD;KAAwC;AACvS;AAIO,MAAMjB,kCAAkCkB,CAAAA;IAC7C,MAAM,EACJC,IAAI,EACL,GAAGD;IACJ,MAAME,gBAAgBhB;IACtBc,MAAMjB,IAAI,CAACoB,SAAS,GAAGC,IAAAA,mBAAY,EAACvB,wBAAwBE,IAAI,EAAEmB,eAAeF,MAAMjB,IAAI,CAACoB,SAAS;IACrG,MAAME,iBAAiBjB;IACvB,MAAMkB,cAAcjB;IACpB,IAAIW,MAAMhB,SAAS,EAAE;QACnBgB,MAAMhB,SAAS,CAACmB,SAAS,GAAGC,IAAAA,mBAAY,EAACvB,wBAAwBG,SAAS,EAAEqB,gBAAgBC,YAAYX,MAAM,EAAEM,SAAS,WAAWK,YAAYf,KAAK,EAAEU,SAAS,iBAAiBK,YAAYZ,UAAU,EAAEM,MAAMhB,SAAS,CAACmB,SAAS;IACpO;IACA,IAAIH,MAAMf,SAAS,EAAE;QACnBe,MAAMf,SAAS,CAACkB,SAAS,GAAGC,IAAAA,mBAAY,EAACvB,wBAAwBI,SAAS,EAAEoB,gBAAgBJ,SAAS,WAAWK,YAAYf,KAAK,EAAEU,SAAS,iBAAiBK,YAAYZ,UAAU,EAAEM,MAAMhB,SAAS,IAAIsB,YAAYT,OAAO,EAAEG,MAAMf,SAAS,CAACkB,SAAS;IACxP;IACA,OAAOH;AACT,GACA,yDAAyD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "RatingItem", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return RatingItem;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
13
|
+
const _useRatingItem = require("./useRatingItem");
|
|
14
|
+
const _renderRatingItem = require("./renderRatingItem");
|
|
15
|
+
const _useRatingItemStylesstyles = require("./useRatingItemStyles.styles");
|
|
16
|
+
const RatingItem = /*#__PURE__*/ _react.forwardRef((props, ref)=>{
|
|
17
|
+
const state = (0, _useRatingItem.useRatingItem_unstable)(props, ref);
|
|
18
|
+
(0, _useRatingItemStylesstyles.useRatingItemStyles_unstable)(state);
|
|
19
|
+
return (0, _renderRatingItem.renderRatingItem_unstable)(state);
|
|
20
|
+
});
|
|
21
|
+
RatingItem.displayName = 'RatingItem';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["RatingItem.js"],"sourcesContent":["import * as React from 'react';\nimport { useRatingItem_unstable } from './useRatingItem';\nimport { renderRatingItem_unstable } from './renderRatingItem';\nimport { useRatingItemStyles_unstable } from './useRatingItemStyles.styles';\n/**\n * RatingItem is an item that will be used to set or display a rating value.\n */ export const RatingItem = /*#__PURE__*/ React.forwardRef((props, ref)=>{\n const state = useRatingItem_unstable(props, ref);\n useRatingItemStyles_unstable(state);\n return renderRatingItem_unstable(state);\n});\nRatingItem.displayName = 'RatingItem';\n"],"names":["RatingItem","React","forwardRef","props","ref","state","useRatingItem_unstable","useRatingItemStyles_unstable","renderRatingItem_unstable","displayName"],"mappings":";;;;+BAMiBA;;;eAAAA;;;;iEANM;+BACgB;kCACG;2CACG;AAGlC,MAAMA,aAAa,WAAW,GAAGC,OAAMC,UAAU,CAAC,CAACC,OAAOC;IACjE,MAAMC,QAAQC,IAAAA,qCAAsB,EAACH,OAAOC;IAC5CG,IAAAA,uDAA4B,EAACF;IAC7B,OAAOG,IAAAA,2CAAyB,EAACH;AACrC;AACAL,WAAWS,WAAW,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _export_star = require("@swc/helpers/_/_export_star");
|
|
6
|
+
_export_star._(require("./RatingItem"), exports);
|
|
7
|
+
_export_star._(require("./RatingItem.types"), exports);
|
|
8
|
+
_export_star._(require("./renderRatingItem"), exports);
|
|
9
|
+
_export_star._(require("./useRatingItem"), exports);
|
|
10
|
+
_export_star._(require("./useRatingItemStyles.styles"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.js"],"sourcesContent":["export * from './RatingItem';\nexport * from './RatingItem.types';\nexport * from './renderRatingItem';\nexport * from './useRatingItem';\nexport * from './useRatingItemStyles.styles';\n"],"names":[],"mappings":";;;;;uBAAc;uBACA;uBACA;uBACA;uBACA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "renderRatingItem_unstable", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return renderRatingItem_unstable;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _jsxruntime = require("@fluentui/react-jsx-runtime/jsx-runtime");
|
|
12
|
+
const _reactutilities = require("@fluentui/react-utilities");
|
|
13
|
+
const renderRatingItem_unstable = (state)=>{
|
|
14
|
+
(0, _reactutilities.assertSlots)(state);
|
|
15
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(state.root, {
|
|
16
|
+
children: [
|
|
17
|
+
state.halfValueInput && /*#__PURE__*/ (0, _jsxruntime.jsx)(state.halfValueInput, {}),
|
|
18
|
+
state.fullValueInput && /*#__PURE__*/ (0, _jsxruntime.jsx)(state.fullValueInput, {}),
|
|
19
|
+
state.unselectedIcon && /*#__PURE__*/ (0, _jsxruntime.jsx)(state.unselectedIcon, {}),
|
|
20
|
+
state.selectedIcon && /*#__PURE__*/ (0, _jsxruntime.jsx)(state.selectedIcon, {})
|
|
21
|
+
]
|
|
22
|
+
});
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["renderRatingItem.js"],"sourcesContent":[" import { jsx as _jsx, jsxs as _jsxs } from \"@fluentui/react-jsx-runtime/jsx-runtime\";\nimport { assertSlots } from '@fluentui/react-utilities';\n/**\n * Render the final JSX of RatingItem\n */ export const renderRatingItem_unstable = (state)=>{\n assertSlots(state);\n return /*#__PURE__*/ _jsxs(state.root, {\n children: [\n state.halfValueInput && /*#__PURE__*/ _jsx(state.halfValueInput, {}),\n state.fullValueInput && /*#__PURE__*/ _jsx(state.fullValueInput, {}),\n state.unselectedIcon && /*#__PURE__*/ _jsx(state.unselectedIcon, {}),\n state.selectedIcon && /*#__PURE__*/ _jsx(state.selectedIcon, {})\n ]\n });\n};\n"],"names":["renderRatingItem_unstable","state","assertSlots","_jsxs","root","children","halfValueInput","_jsx","fullValueInput","unselectedIcon","selectedIcon"],"mappings":";;;;+BAIiBA;;;eAAAA;;;4BAJ4B;gCACjB;AAGjB,MAAMA,4BAA4B,CAACC;IAC1CC,IAAAA,2BAAW,EAACD;IACZ,OAAO,WAAW,GAAGE,IAAAA,gBAAK,EAACF,MAAMG,IAAI,EAAE;QACnCC,UAAU;YACNJ,MAAMK,cAAc,IAAI,WAAW,GAAGC,IAAAA,eAAI,EAACN,MAAMK,cAAc,EAAE,CAAC;YAClEL,MAAMO,cAAc,IAAI,WAAW,GAAGD,IAAAA,eAAI,EAACN,MAAMO,cAAc,EAAE,CAAC;YAClEP,MAAMQ,cAAc,IAAI,WAAW,GAAGF,IAAAA,eAAI,EAACN,MAAMQ,cAAc,EAAE,CAAC;YAClER,MAAMS,YAAY,IAAI,WAAW,GAAGH,IAAAA,eAAI,EAACN,MAAMS,YAAY,EAAE,CAAC;SACjE;IACL;AACJ"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useRatingItem_unstable", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useRatingItem_unstable;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
13
|
+
const _reactutilities = require("@fluentui/react-utilities");
|
|
14
|
+
const _reacttabster = require("@fluentui/react-tabster");
|
|
15
|
+
const _RatingItemContext = require("../../contexts/RatingItemContext");
|
|
16
|
+
const defaultItemLabel = (num)=>num + '';
|
|
17
|
+
const useRatingItem_unstable = (props, ref)=>{
|
|
18
|
+
const context = (0, _RatingItemContext.useRatingItemContextValue_unstable)();
|
|
19
|
+
const { value = 0 } = props;
|
|
20
|
+
const { itemLabel = defaultItemLabel, iconFilled: IconFilled, iconOutline: IconOutline } = context;
|
|
21
|
+
const ratingValue = Math.round((context.value || 0) * 2) / 2; // round to the nearest 0.5
|
|
22
|
+
var _context_hoveredValue;
|
|
23
|
+
const displayedRatingValue = (_context_hoveredValue = context.hoveredValue) !== null && _context_hoveredValue !== void 0 ? _context_hoveredValue : ratingValue;
|
|
24
|
+
const appearance = context.interactive ? 'outline' : 'filled';
|
|
25
|
+
let iconFillWidth;
|
|
26
|
+
if (context.compact || displayedRatingValue >= value) {
|
|
27
|
+
iconFillWidth = 1;
|
|
28
|
+
} else if (displayedRatingValue >= value - 0.5) {
|
|
29
|
+
iconFillWidth = 0.5;
|
|
30
|
+
} else {
|
|
31
|
+
iconFillWidth = 0;
|
|
32
|
+
}
|
|
33
|
+
const root = _reactutilities.slot.always((0, _reactutilities.getIntrinsicElementProps)('span', {
|
|
34
|
+
ref: (0, _reactutilities.useMergedRefs)((0, _reacttabster.useFocusWithin)(), ref),
|
|
35
|
+
...props
|
|
36
|
+
}), {
|
|
37
|
+
elementType: 'span'
|
|
38
|
+
});
|
|
39
|
+
let unselectedIcon;
|
|
40
|
+
if (iconFillWidth < 1) {
|
|
41
|
+
unselectedIcon = _reactutilities.slot.always(props.unselectedIcon, {
|
|
42
|
+
defaultProps: {
|
|
43
|
+
children: appearance === 'filled' ? /*#__PURE__*/ _react.createElement(IconFilled, null) : /*#__PURE__*/ _react.createElement(IconOutline, null),
|
|
44
|
+
'aria-hidden': true
|
|
45
|
+
},
|
|
46
|
+
elementType: 'div'
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
let selectedIcon;
|
|
50
|
+
if (iconFillWidth > 0) {
|
|
51
|
+
selectedIcon = _reactutilities.slot.always(props.selectedIcon, {
|
|
52
|
+
defaultProps: {
|
|
53
|
+
children: /*#__PURE__*/ _react.createElement(IconFilled, null),
|
|
54
|
+
'aria-hidden': true
|
|
55
|
+
},
|
|
56
|
+
elementType: 'div'
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
let halfValueInput;
|
|
60
|
+
if (context.interactive && context.step === 0.5) {
|
|
61
|
+
halfValueInput = _reactutilities.slot.always(props.halfValueInput, {
|
|
62
|
+
defaultProps: {
|
|
63
|
+
type: 'radio',
|
|
64
|
+
name: context.name,
|
|
65
|
+
value: value - 0.5,
|
|
66
|
+
checked: ratingValue === value - 0.5,
|
|
67
|
+
'aria-label': itemLabel(value - 0.5),
|
|
68
|
+
onChange: ()=>{
|
|
69
|
+
// This empty onChange handler silences an incorrect React warning about not using onChange for a controlled input.
|
|
70
|
+
// The parent Rating component has the real onChange handler to listen to change events from this input.
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
elementType: 'input'
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
let fullValueInput;
|
|
77
|
+
if (context.interactive) {
|
|
78
|
+
fullValueInput = _reactutilities.slot.always(props.fullValueInput, {
|
|
79
|
+
defaultProps: {
|
|
80
|
+
type: 'radio',
|
|
81
|
+
name: context.name,
|
|
82
|
+
value,
|
|
83
|
+
checked: ratingValue === value,
|
|
84
|
+
'aria-label': itemLabel(value),
|
|
85
|
+
onChange: ()=>{
|
|
86
|
+
// This empty onChange handler silences an incorrect React warning about not using onChange for a controlled input.
|
|
87
|
+
// The parent Rating component has the real onChange handler to listen to change events from this input.
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
elementType: 'input'
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const state = {
|
|
94
|
+
appearance,
|
|
95
|
+
color: context.color,
|
|
96
|
+
step: context.step,
|
|
97
|
+
size: context.size,
|
|
98
|
+
iconFillWidth,
|
|
99
|
+
value,
|
|
100
|
+
components: {
|
|
101
|
+
root: 'span',
|
|
102
|
+
selectedIcon: 'div',
|
|
103
|
+
unselectedIcon: 'div',
|
|
104
|
+
halfValueInput: 'input',
|
|
105
|
+
fullValueInput: 'input'
|
|
106
|
+
},
|
|
107
|
+
root,
|
|
108
|
+
selectedIcon,
|
|
109
|
+
unselectedIcon,
|
|
110
|
+
halfValueInput,
|
|
111
|
+
fullValueInput
|
|
112
|
+
};
|
|
113
|
+
return state;
|
|
114
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useRatingItem.js"],"sourcesContent":["import * as React from 'react';\nimport { getIntrinsicElementProps, slot, useMergedRefs } from '@fluentui/react-utilities';\nimport { useFocusWithin } from '@fluentui/react-tabster';\nimport { useRatingItemContextValue_unstable } from '../../contexts/RatingItemContext';\nconst defaultItemLabel = (num)=>num + '';\n/**\n * Create the state required to render RatingItem.\n *\n * The returned state can be modified with hooks such as useRatingItemStyles_unstable,\n * before being passed to renderRatingItem_unstable.\n *\n * @param props - props from this instance of RatingItem\n * @param ref - reference to root HTMLElement of RatingItem\n */ export const useRatingItem_unstable = (props, ref)=>{\n const context = useRatingItemContextValue_unstable();\n const { value = 0 } = props;\n const { itemLabel = defaultItemLabel, iconFilled: IconFilled, iconOutline: IconOutline } = context;\n const ratingValue = Math.round((context.value || 0) * 2) / 2; // round to the nearest 0.5\n var _context_hoveredValue;\n const displayedRatingValue = (_context_hoveredValue = context.hoveredValue) !== null && _context_hoveredValue !== void 0 ? _context_hoveredValue : ratingValue;\n const appearance = context.interactive ? 'outline' : 'filled';\n let iconFillWidth;\n if (context.compact || displayedRatingValue >= value) {\n iconFillWidth = 1;\n } else if (displayedRatingValue >= value - 0.5) {\n iconFillWidth = 0.5;\n } else {\n iconFillWidth = 0;\n }\n const root = slot.always(getIntrinsicElementProps('span', {\n ref: useMergedRefs(useFocusWithin(), ref),\n ...props\n }), {\n elementType: 'span'\n });\n let unselectedIcon;\n if (iconFillWidth < 1) {\n unselectedIcon = slot.always(props.unselectedIcon, {\n defaultProps: {\n children: appearance === 'filled' ? /*#__PURE__*/ React.createElement(IconFilled, null) : /*#__PURE__*/ React.createElement(IconOutline, null),\n 'aria-hidden': true\n },\n elementType: 'div'\n });\n }\n let selectedIcon;\n if (iconFillWidth > 0) {\n selectedIcon = slot.always(props.selectedIcon, {\n defaultProps: {\n children: /*#__PURE__*/ React.createElement(IconFilled, null),\n 'aria-hidden': true\n },\n elementType: 'div'\n });\n }\n let halfValueInput;\n if (context.interactive && context.step === 0.5) {\n halfValueInput = slot.always(props.halfValueInput, {\n defaultProps: {\n type: 'radio',\n name: context.name,\n value: value - 0.5,\n checked: ratingValue === value - 0.5,\n 'aria-label': itemLabel(value - 0.5),\n onChange: ()=>{\n // This empty onChange handler silences an incorrect React warning about not using onChange for a controlled input.\n // The parent Rating component has the real onChange handler to listen to change events from this input.\n }\n },\n elementType: 'input'\n });\n }\n let fullValueInput;\n if (context.interactive) {\n fullValueInput = slot.always(props.fullValueInput, {\n defaultProps: {\n type: 'radio',\n name: context.name,\n value,\n checked: ratingValue === value,\n 'aria-label': itemLabel(value),\n onChange: ()=>{\n // This empty onChange handler silences an incorrect React warning about not using onChange for a controlled input.\n // The parent Rating component has the real onChange handler to listen to change events from this input.\n }\n },\n elementType: 'input'\n });\n }\n const state = {\n appearance,\n color: context.color,\n step: context.step,\n size: context.size,\n iconFillWidth,\n value,\n components: {\n root: 'span',\n selectedIcon: 'div',\n unselectedIcon: 'div',\n halfValueInput: 'input',\n fullValueInput: 'input'\n },\n root,\n selectedIcon,\n unselectedIcon,\n halfValueInput,\n fullValueInput\n };\n return state;\n};\n"],"names":["useRatingItem_unstable","defaultItemLabel","num","props","ref","context","useRatingItemContextValue_unstable","value","itemLabel","iconFilled","IconFilled","iconOutline","IconOutline","ratingValue","Math","round","_context_hoveredValue","displayedRatingValue","hoveredValue","appearance","interactive","iconFillWidth","compact","root","slot","always","getIntrinsicElementProps","useMergedRefs","useFocusWithin","elementType","unselectedIcon","defaultProps","children","React","createElement","selectedIcon","halfValueInput","step","type","name","checked","onChange","fullValueInput","state","color","size","components"],"mappings":"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"}
|