@hh.ru/magritte-ui-rating-review 1.0.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/RatingReview.d.ts +37 -0
- package/RatingReview.js +39 -0
- package/RatingReview.js.map +1 -0
- package/index.css +42 -0
- package/index.d.ts +2 -0
- package/index.js +10 -0
- package/index.js.map +1 -0
- package/index.mock.d.ts +5 -0
- package/index.mock.js +16 -0
- package/index.mock.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type RatingReviewSize = 'small' | 'medium';
|
|
2
|
+
export interface RatingReviewProps {
|
|
3
|
+
'data-qa'?: string;
|
|
4
|
+
/** Значение */
|
|
5
|
+
value: number | null;
|
|
6
|
+
'aria-describedby'?: string;
|
|
7
|
+
/** Размер */
|
|
8
|
+
size: RatingReviewSize;
|
|
9
|
+
}
|
|
10
|
+
export declare const ICON_BY_SIZE: {
|
|
11
|
+
readonly small: {
|
|
12
|
+
readonly filled: import("../../icon/src").IconWrapperComponentSize16<null> & {
|
|
13
|
+
Skeleton: import("../../icon/src").IconWrapperComponentSize16<{
|
|
14
|
+
loading?: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
readonly outline: import("../../icon/src").IconWrapperComponentSize16<null> & {
|
|
18
|
+
Skeleton: import("../../icon/src").IconWrapperComponentSize16<{
|
|
19
|
+
loading?: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
readonly medium: {
|
|
24
|
+
readonly filled: import("../../icon/src").IconWrapperComponentSize24<null> & {
|
|
25
|
+
Skeleton: import("../../icon/src").IconWrapperComponentSize24<{
|
|
26
|
+
loading?: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
};
|
|
29
|
+
readonly outline: import("../../icon/src").IconWrapperComponentSize24<null> & {
|
|
30
|
+
Skeleton: import("../../icon/src").IconWrapperComponentSize24<{
|
|
31
|
+
loading?: boolean;
|
|
32
|
+
}>;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export declare const normalizeRatingValue: (value: number | null) => number;
|
|
37
|
+
export declare const RatingReview: import("react").ForwardRefExoticComponent<RatingReviewProps & import("react").RefAttributes<HTMLElement>>;
|
package/RatingReview.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { useDisabled } from '@hh.ru/magritte-common-use-disabled';
|
|
6
|
+
import { StarFilledSize16, StarOutlinedSize16, StarFilledSize24, StarOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';
|
|
7
|
+
import { Text } from '@hh.ru/magritte-ui-typography';
|
|
8
|
+
|
|
9
|
+
var styles = {"rating-review":"magritte-rating-review___X1HDg_1-0-1","ratingReview":"magritte-rating-review___X1HDg_1-0-1","internal-container":"magritte-internal-container___Tutx7_1-0-1","internalContainer":"magritte-internal-container___Tutx7_1-0-1","size-medium":"magritte-size-medium___wVwww_1-0-1","sizeMedium":"magritte-size-medium___wVwww_1-0-1","disabled":"magritte-disabled___uGGmU_1-0-1","has-rating":"magritte-has-rating___BoybH_1-0-1","hasRating":"magritte-has-rating___BoybH_1-0-1"};
|
|
10
|
+
|
|
11
|
+
const ICON_BY_SIZE = {
|
|
12
|
+
small: {
|
|
13
|
+
filled: StarFilledSize16,
|
|
14
|
+
outline: StarOutlinedSize16,
|
|
15
|
+
},
|
|
16
|
+
medium: {
|
|
17
|
+
filled: StarFilledSize24,
|
|
18
|
+
outline: StarOutlinedSize24,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const normalizeRatingValue = (value) => value ? Math.round(Math.min(Math.max(value, 0), 5) * 2) / 2 : 0;
|
|
22
|
+
const RatingReview = forwardRef(({ 'data-qa': dataQa, value, 'aria-describedby': describedBy, size = 'small' }, ref) => {
|
|
23
|
+
const normalizedValue = normalizeRatingValue(value);
|
|
24
|
+
const isDisabled = useDisabled();
|
|
25
|
+
const fractionDigits = normalizedValue === 0 ? 0 : 1;
|
|
26
|
+
const Icon = ICON_BY_SIZE[size][normalizedValue > 0 ? 'filled' : 'outline'];
|
|
27
|
+
return (jsx("div", { role: "img", "aria-label": normalizedValue.toLocaleString(), "data-qa": dataQa, "aria-describedby": describedBy, ref: ref, className: classnames(styles.ratingReview, {
|
|
28
|
+
[styles.sizeMedium]: size === 'medium',
|
|
29
|
+
[styles.hasRating]: normalizedValue > 0,
|
|
30
|
+
[styles.disabled]: isDisabled,
|
|
31
|
+
}), children: jsxs("div", { className: styles.internalContainer, "aria-hidden": true, children: [jsx(Icon, {}), jsx(Text, { typography: size === 'small' ? 'subtitle-4-semibold' : 'title-4-semibold', children: normalizedValue.toLocaleString(undefined, {
|
|
32
|
+
maximumFractionDigits: fractionDigits,
|
|
33
|
+
minimumFractionDigits: fractionDigits,
|
|
34
|
+
}) })] }) }));
|
|
35
|
+
});
|
|
36
|
+
RatingReview.displayName = 'RatingReview';
|
|
37
|
+
|
|
38
|
+
export { ICON_BY_SIZE, RatingReview, normalizeRatingValue };
|
|
39
|
+
//# sourceMappingURL=RatingReview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RatingReview.js","sources":["../src/RatingReview.tsx"],"sourcesContent":["import { forwardRef, type LegacyRef } from 'react';\nimport classnames from 'classnames';\n\nimport { useDisabled } from '@hh.ru/magritte-common-use-disabled';\nimport {\n StarFilledSize16,\n StarOutlinedSize16,\n StarFilledSize24,\n StarOutlinedSize24,\n} from '@hh.ru/magritte-ui-icon/icon';\nimport { Text } from '@hh.ru/magritte-ui-typography';\n\nimport styles from './rating-review.less';\n\nexport type RatingReviewSize = 'small' | 'medium';\n\nexport interface RatingReviewProps {\n 'data-qa'?: string;\n /** Значение */\n value: number | null;\n 'aria-describedby'?: string;\n /** Размер */\n size: RatingReviewSize;\n}\n\nexport const ICON_BY_SIZE = {\n small: {\n filled: StarFilledSize16,\n outline: StarOutlinedSize16,\n },\n medium: {\n filled: StarFilledSize24,\n outline: StarOutlinedSize24,\n },\n} as const;\n\nexport const normalizeRatingValue = (value: number | null): number =>\n value ? Math.round(Math.min(Math.max(value, 0), 5) * 2) / 2 : 0;\n\nexport const RatingReview = forwardRef<HTMLElement, RatingReviewProps>(\n ({ 'data-qa': dataQa, value, 'aria-describedby': describedBy, size = 'small' }, ref) => {\n const normalizedValue = normalizeRatingValue(value);\n const isDisabled = useDisabled();\n const fractionDigits = normalizedValue === 0 ? 0 : 1;\n const Icon = ICON_BY_SIZE[size][normalizedValue > 0 ? 'filled' : 'outline'];\n\n return (\n <div\n role=\"img\"\n aria-label={normalizedValue.toLocaleString()}\n data-qa={dataQa}\n aria-describedby={describedBy}\n ref={ref as LegacyRef<HTMLDivElement>}\n className={classnames(styles.ratingReview, {\n [styles.sizeMedium]: size === 'medium',\n [styles.hasRating]: normalizedValue > 0,\n [styles.disabled]: isDisabled,\n })}\n >\n <div className={styles.internalContainer} aria-hidden>\n <Icon />\n <Text typography={size === 'small' ? 'subtitle-4-semibold' : 'title-4-semibold'}>\n {normalizedValue.toLocaleString(undefined, {\n maximumFractionDigits: fractionDigits,\n minimumFractionDigits: fractionDigits,\n })}\n </Text>\n </div>\n </div>\n );\n }\n);\n\nRatingReview.displayName = 'RatingReview';\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;;AAyBa,MAAA,YAAY,GAAG;AACxB,IAAA,KAAK,EAAE;AACH,QAAA,MAAM,EAAE,gBAAgB;AACxB,QAAA,OAAO,EAAE,kBAAkB;AAC9B,KAAA;AACD,IAAA,MAAM,EAAE;AACJ,QAAA,MAAM,EAAE,gBAAgB;AACxB,QAAA,OAAO,EAAE,kBAAkB;AAC9B,KAAA;EACM;AAEE,MAAA,oBAAoB,GAAG,CAAC,KAAoB,KACrD,KAAK,GAAG,IAAI,CAAC,KAAK,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AAK,OAAO,GAAG,qBAAqB,GAAG,kBAAkB,YAC1E,eAAe,CAAC,cAAc,CAAC,SAAS,EAAE;AACvC,wBAAA,qBAAqB,EAAE,cAAc;AACrC,wBAAA,qBAAqB,EAAE,cAAc;AACxC,qBAAA,CAAC,EACC,CAAA,CAAA,EAAA,CACL,EACJ,CAAA,EACR;AACN,CAAC,EACH;AAEF,YAAY,CAAC,WAAW,GAAG,cAAc;;;;"}
|
package/index.css
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
:root{
|
|
2
|
+
--magritte-color-text-primary-v21-4-6:#000000;
|
|
3
|
+
--magritte-color-text-state-primary-disabled-v21-4-6:#0000007a;
|
|
4
|
+
--magritte-color-icon-tertiary-v21-4-6:#AABBCA;
|
|
5
|
+
--magritte-color-icon-warning-v21-4-6:#ff9900;
|
|
6
|
+
--magritte-color-icon-state-tertiary-disabled-v21-4-6:#aabbca7a;
|
|
7
|
+
--magritte-color-icon-state-warning-disabled-v21-4-6:#ff99007a;
|
|
8
|
+
}
|
|
9
|
+
.magritte-night-theme{
|
|
10
|
+
--magritte-color-text-primary-v21-4-6:#ffffff;
|
|
11
|
+
--magritte-color-text-state-primary-disabled-v21-4-6:#ababab7a;
|
|
12
|
+
--magritte-color-icon-tertiary-v21-4-6:#767676;
|
|
13
|
+
--magritte-color-icon-warning-v21-4-6:#EB8D05;
|
|
14
|
+
--magritte-color-icon-state-tertiary-disabled-v21-4-6:#767676;
|
|
15
|
+
--magritte-color-icon-state-warning-disabled-v21-4-6:#eb8d057a;
|
|
16
|
+
}
|
|
17
|
+
.magritte-rating-review___X1HDg_1-0-1{
|
|
18
|
+
display:inline-block;
|
|
19
|
+
--magritte-ui-icon-color-override:var(--magritte-color-icon-tertiary-v21-4-6);
|
|
20
|
+
--magritte-ui-text-color-override:var(--magritte-color-text-primary-v21-4-6);
|
|
21
|
+
}
|
|
22
|
+
.magritte-internal-container___Tutx7_1-0-1{
|
|
23
|
+
display:inline-flex;
|
|
24
|
+
flex-wrap:nowrap;
|
|
25
|
+
gap:6px;
|
|
26
|
+
align-items:center;
|
|
27
|
+
justify-content:center;
|
|
28
|
+
height:22px;
|
|
29
|
+
}
|
|
30
|
+
.magritte-size-medium___wVwww_1-0-1 .magritte-internal-container___Tutx7_1-0-1{
|
|
31
|
+
height:32px;
|
|
32
|
+
}
|
|
33
|
+
.magritte-disabled___uGGmU_1-0-1{
|
|
34
|
+
--magritte-ui-icon-color-override:var(--magritte-color-icon-state-tertiary-disabled-v21-4-6);
|
|
35
|
+
--magritte-ui-text-color-override:var(--magritte-color-text-state-primary-disabled-v21-4-6);
|
|
36
|
+
}
|
|
37
|
+
.magritte-disabled___uGGmU_1-0-1.magritte-has-rating___BoybH_1-0-1{
|
|
38
|
+
--magritte-ui-icon-color-override:var(--magritte-color-icon-state-warning-disabled-v21-4-6);
|
|
39
|
+
}
|
|
40
|
+
.magritte-has-rating___BoybH_1-0-1{
|
|
41
|
+
--magritte-ui-icon-color-override:var(--magritte-color-icon-warning-v21-4-6);
|
|
42
|
+
}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
export * from '@hh.ru/magritte-ui-theme-provider';
|
|
3
|
+
export { ICON_BY_SIZE, RatingReview, normalizeRatingValue } from './RatingReview.js';
|
|
4
|
+
import 'react/jsx-runtime';
|
|
5
|
+
import 'react';
|
|
6
|
+
import 'classnames';
|
|
7
|
+
import '@hh.ru/magritte-common-use-disabled';
|
|
8
|
+
import '@hh.ru/magritte-ui-icon/icon';
|
|
9
|
+
import '@hh.ru/magritte-ui-typography';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
package/index.mock.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ForwardRefExoticComponent } from 'react';
|
|
2
|
+
export { type RatingReviewProps, type RatingReviewSize, normalizeRatingValue, } from '@hh.ru/magritte-ui-rating-review/RatingReview';
|
|
3
|
+
declare const ThemeProvider: any;
|
|
4
|
+
export { ThemeProvider };
|
|
5
|
+
export declare const RatingReview: ForwardRefExoticComponent<Record<string, unknown>>;
|
package/index.mock.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { mockComponent } from '@hh.ru/magritte-ui-mock-component';
|
|
3
|
+
export { normalizeRatingValue } from './RatingReview.js';
|
|
4
|
+
import 'react/jsx-runtime';
|
|
5
|
+
import 'react';
|
|
6
|
+
import 'classnames';
|
|
7
|
+
import '@hh.ru/magritte-common-use-disabled';
|
|
8
|
+
import '@hh.ru/magritte-ui-icon/icon';
|
|
9
|
+
import '@hh.ru/magritte-ui-typography';
|
|
10
|
+
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
12
|
+
const { ThemeProvider } = jest.requireActual('@hh.ru/magritte-ui-theme-provider/index');
|
|
13
|
+
const RatingReview = mockComponent('RatingReview');
|
|
14
|
+
|
|
15
|
+
export { RatingReview, ThemeProvider };
|
|
16
|
+
//# sourceMappingURL=index.mock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mock.js","sources":["../src/index.mock.ts"],"sourcesContent":["import { ForwardRefExoticComponent } from 'react';\n\nimport { mockComponent } from '@hh.ru/magritte-ui-mock-component';\n\nexport {\n type RatingReviewProps,\n type RatingReviewSize,\n normalizeRatingValue,\n} from '@hh.ru/magritte-ui-rating-review/RatingReview';\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\nconst { ThemeProvider } = jest.requireActual('@hh.ru/magritte-ui-theme-provider/index');\n\nexport { ThemeProvider };\n\nexport const RatingReview: ForwardRefExoticComponent<Record<string, unknown>> = mockComponent('RatingReview');\n"],"names":[],"mappings":";;;;;;;;;AAUA;AACM,MAAA,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC,aAAa,CAAC,yCAAyC,EAAE;MAI3E,YAAY,GAAuD,aAAa,CAAC,cAAc;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hh.ru/magritte-ui-rating-review",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"types": "index.d.ts",
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"index.css"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "yarn root:build $(pwd)",
|
|
11
|
+
"build-test-branch": "yarn root:build-test-branch $(pwd)",
|
|
12
|
+
"prepack": "yarn root:prepack $(pwd)",
|
|
13
|
+
"postpublish": "yarn root:postpublish $(pwd)",
|
|
14
|
+
"stylelint-check": "yarn root:stylelint-check $(pwd)",
|
|
15
|
+
"eslint-check": "yarn root:eslint-check $(pwd)",
|
|
16
|
+
"ts-config": "yarn root:ts-config $(pwd)",
|
|
17
|
+
"ts-check": "yarn root:ts-check $(pwd)",
|
|
18
|
+
"test": "yarn root:test $(pwd)",
|
|
19
|
+
"watch": "yarn root:watch $(pwd)"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"classnames": ">=2.3.2",
|
|
26
|
+
"react": ">=18.2.0"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@hh.ru/magritte-common-use-disabled": "1.0.12",
|
|
30
|
+
"@hh.ru/magritte-design-tokens": "21.4.6",
|
|
31
|
+
"@hh.ru/magritte-ui-icon": "11.0.9",
|
|
32
|
+
"@hh.ru/magritte-ui-mock-component": "1.1.4",
|
|
33
|
+
"@hh.ru/magritte-ui-theme-provider": "1.1.48",
|
|
34
|
+
"@hh.ru/magritte-ui-typography": "3.0.43"
|
|
35
|
+
},
|
|
36
|
+
"gitHead": "fd604c1be8a7af9fe6b04eb309317bd1d20235b6"
|
|
37
|
+
}
|