@cleartrip/ct-design-rating 2.0.0-TEST.3 → 4.0.0-SNAPSHOT-rnfinaltest.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -0
- package/dist/Rating.d.ts +4 -3
- package/dist/Rating.d.ts.map +1 -1
- package/dist/ct-design-rating.browser.cjs.js +1 -1
- package/dist/ct-design-rating.browser.cjs.js.map +1 -1
- package/dist/ct-design-rating.browser.esm.js +1 -1
- package/dist/ct-design-rating.browser.esm.js.map +1 -1
- package/dist/ct-design-rating.cjs.js +54 -92
- package/dist/ct-design-rating.cjs.js.map +1 -1
- package/dist/ct-design-rating.esm.js +55 -93
- package/dist/ct-design-rating.esm.js.map +1 -1
- package/dist/ct-design-rating.umd.js +55 -822
- package/dist/ct-design-rating.umd.js.map +1 -1
- package/dist/style.d.ts +9 -35
- package/dist/style.d.ts.map +1 -1
- package/dist/type.d.ts +17 -23
- package/dist/type.d.ts.map +1 -1
- package/package.json +20 -12
- package/src/Rating.tsx +51 -0
- package/src/index.ts +2 -0
- package/src/style.ts +42 -0
- package/src/type.ts +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Rating
|
|
2
|
+
|
|
3
|
+
A component for displaying and collecting star ratings.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @cleartrip/ct-design-rating
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @cleartrip/ct-design-rating
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Peer dependencies
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# Required for all targets
|
|
19
|
+
npm install react
|
|
20
|
+
|
|
21
|
+
# Web only
|
|
22
|
+
npm install react-dom
|
|
23
|
+
|
|
24
|
+
# React Native only
|
|
25
|
+
npm install react-native
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### Basic
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { Rating } from '@cleartrip/ct-design-rating';
|
|
36
|
+
|
|
37
|
+
function Example() {
|
|
38
|
+
return (
|
|
39
|
+
<Rating>
|
|
40
|
+
{/* Basic usage */}
|
|
41
|
+
</Rating>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Props
|
|
49
|
+
|
|
50
|
+
| Prop | Type | Default | Required | Description |
|
|
51
|
+
|------|------|---------|----------|-------------|
|
|
52
|
+
| `rating` | `number` | — | Yes | rating property |
|
|
53
|
+
| `maxRating` | `number` | — | No | maxRating property |
|
|
54
|
+
| `size` | `RatingSizeType` | — | No | size property |
|
|
55
|
+
| `activeColor` | `string` | — | No | activeColor property |
|
|
56
|
+
| `inActiveColor` | `string` | — | No | inActiveColor property |
|
|
57
|
+
| `styleConfig` | `{` | — | No | styleConfig property |
|
|
58
|
+
| `root` | `Styles[]` | — | No | root property |
|
|
59
|
+
| `ratingContainer` | `Styles[]` | — | No | ratingContainer property |
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## RatingSize
|
|
64
|
+
|
|
65
|
+
- `XS` — xs
|
|
66
|
+
- `SM` — sm
|
|
67
|
+
- `MD` — md
|
|
68
|
+
- `LG` — lg
|
|
69
|
+
- `XL` — xl
|
|
70
|
+
- `XXL` — xxl
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Accessibility
|
|
74
|
+
|
|
75
|
+
- The component follows accessibility best practices
|
|
76
|
+
- Ensure proper ARIA attributes are provided where needed
|
|
77
|
+
- Test with screen readers to ensure usability
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Migration
|
|
82
|
+
|
|
83
|
+
If migrating from a previous version:
|
|
84
|
+
|
|
85
|
+
```diff
|
|
86
|
+
- import { Rating } from 'yagami/core/components';
|
|
87
|
+
+ import { Rating } from '@cleartrip/ct-design-rating';
|
|
88
|
+
```
|
package/dist/Rating.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ContainerRef } from '@cleartrip/ct-design-container';
|
|
3
|
+
import { IRatingProps } from './type';
|
|
4
|
+
declare const Rating: React.ForwardRefExoticComponent<IRatingProps & React.RefAttributes<ContainerRef>>;
|
|
4
5
|
export default Rating;
|
|
5
6
|
//# sourceMappingURL=Rating.d.ts.map
|
package/dist/Rating.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Rating.d.ts","sourceRoot":"","sources":["../packages/components/Rating/src/Rating.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"Rating.d.ts","sourceRoot":"","sources":["../packages/components/Rating/src/Rating.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAGnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAMnE,OAAO,EAAE,YAAY,EAAc,MAAM,QAAQ,CAAC;AAalD,QAAA,MAAM,MAAM,mFAwBV,CAAC;AAIH,eAAe,MAAM,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var e,i=require("react/jsx-runtime"),t=require("react"),r=require("@cleartrip/ct-design-container"),n=require("@cleartrip/ct-design-icons"),s=require("@cleartrip/ct-design-theme"),o=require("@cleartrip/ct-design-style-manager");exports.RatingSize=void 0,(e=exports.RatingSize||(exports.RatingSize={})).XS="xs",e.SM="sm",e.MD="md",e.LG="lg",e.XL="xl",e.XXL="xxl";const a=(e,i)=>Object.assign(Object.assign({},((e,i)=>{switch(i){case exports.RatingSize.XS:return{width:e.size[2],height:e.size[2]};case exports.RatingSize.SM:return{width:e.size[4],height:e.size[4]};case exports.RatingSize.MD:return{width:e.size[5],height:e.size[5]};case exports.RatingSize.LG:return{width:e.size[6],height:e.size[6]};case exports.RatingSize.XL:return{width:e.size[8],height:e.size[8]};case exports.RatingSize.XXL:return{width:e.size[10],height:e.size[10]};default:return{width:e.size[4],height:e.size[4]}}})(e,i)),(e=>({activeColor:e.color.text.primary,inActiveColor:e.color.text.tertiary}))(e)),g=o.makeStyles(e=>({root:{flexDirection:"row",padding:null==e?void 0:e.spacing[1],width:"100%"},ratingContainer:{flexDirection:"row"}})),c=t.forwardRef((e,o)=>{const{rating:c=2,maxRating:h=5,size:l=exports.RatingSize.LG,activeColor:z,inActiveColor:d,styleConfig:x}=e,u=s.useTheme(),p=t.useMemo(()=>a(u,l),[u,l]),{root:S=[],ratingContainer:w=[]}=x||{};return i.jsx(r.Container,{ref:o,styleConfig:{root:[g.root,...S]},children:Array.from({length:h},(e,t)=>{const s=t+1<=c?z||p.activeColor:d||p.inActiveColor;return i.jsx(r.Container,{styleConfig:{root:[g.ratingContainer,...w]},children:i.jsx(n.StarIcon,{fill:s,stroke:s,width:p.width,height:p.height})},`rating_${t}`)})})});c.displayName="Rating",exports.Rating=c;
|
|
2
2
|
//# sourceMappingURL=ct-design-rating.browser.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ct-design-rating.browser.cjs.js","sources":["../packages/components/Rating/src/type.ts","../packages/components/Rating/src/style.ts","../packages/components/Rating/src/Rating.tsx"],"sourcesContent":[null,null,null],"names":["
|
|
1
|
+
{"version":3,"file":"ct-design-rating.browser.cjs.js","sources":["../packages/components/Rating/src/type.ts","../packages/components/Rating/src/style.ts","../packages/components/Rating/src/Rating.tsx"],"sourcesContent":[null,null,null],"names":["RatingSize","getRatingTokens","theme","size","Object","assign","XS","width","height","SM","MD","LG","XL","XXL","getRatingSizeTokens","activeColor","color","text","primary","inActiveColor","tertiary","getRatingColorTokens","staticRatingStyles","makeStyles","root","flexDirection","padding","spacing","ratingContainer","Rating","forwardRef","props","ref","rating","maxRating","styleConfig","useTheme","tokens","useMemo","customRootStyles","customRatingContainer","_jsx","jsx","Container","children","Array","from","length","_","index","fill","StarIcon","stroke","displayName"],"mappings":"iBAGYA,gOAAAA,QAOXA,gBAAA,GAPWA,EAAAA,QAAUA,aAAVA,mBAOX,CAAA,IANC,GAAA,KACAA,EAAA,GAAA,KACAA,EAAA,GAAA,KACAA,EAAA,GAAA,KACAA,EAAA,GAAA,KACAA,EAAA,IAAA,MCKK,MAwBMC,EAAkB,CAACC,EAAcC,IAA+DC,OAAAC,OAAAD,OAAAC,OAAA,CAAA,EAxB1E,EAACH,EAAcC,KAChD,OAAQA,GACN,KAAKH,QAAUA,WAACM,GACd,MAAO,CAAEC,MAAOL,EAAMC,KAAK,GAAIK,OAAQN,EAAMC,KAAK,IACpD,KAAKH,QAAUA,WAACS,GACd,MAAO,CAAEF,MAAOL,EAAMC,KAAK,GAAIK,OAAQN,EAAMC,KAAK,IACpD,KAAKH,QAAUA,WAACU,GACd,MAAO,CAAEH,MAAOL,EAAMC,KAAK,GAAIK,OAAQN,EAAMC,KAAK,IACpD,KAAKH,QAAUA,WAACW,GACd,MAAO,CAAEJ,MAAOL,EAAMC,KAAK,GAAIK,OAAQN,EAAMC,KAAK,IACpD,KAAKH,QAAUA,WAACY,GACd,MAAO,CAAEL,MAAOL,EAAMC,KAAK,GAAIK,OAAQN,EAAMC,KAAK,IACpD,KAAKH,QAAUA,WAACa,IACd,MAAO,CAAEN,MAAOL,EAAMC,KAAK,IAAKK,OAAQN,EAAMC,KAAK,KACrD,QACE,MAAO,CAAEI,MAAOL,EAAMC,KAAK,GAAIK,OAAQN,EAAMC,KAAK,MAUnDW,CAAoBZ,EAAOC,IANI,CAACD,IAAqC,CACxEa,YAAab,EAAMc,MAAMC,KAAKC,QAC9BC,cAAejB,EAAMc,MAAMC,KAAKG,WAK7BC,CAAqBnB,IC7BpBoB,EAAqBC,EAAAA,WAAYrB,IAAW,CAChDsB,KAAM,CACJC,cAAe,MACfC,QAASxB,aAAK,EAALA,EAAOyB,QAAQ,GACxBpB,MAAO,QAETqB,gBAAiB,CACfH,cAAe,UAIbI,EAASC,EAAUA,WAA6B,CAACC,EAAOC,KAC5D,MAAMC,OAAEA,EAAS,EAACC,UAAEA,EAAY,EAAC/B,KAAEA,EAAOH,mBAAWW,GAAEI,YAAEA,EAAWI,cAAEA,EAAagB,YAAEA,GAAgBJ,EAC/F7B,EAAQkC,EAAAA,WAERC,EAASC,UAAQ,IAAMrC,EAAgBC,EAAOC,GAAO,CAACD,EAAOC,KAE3DqB,KAAMe,EAAmB,GAAIX,gBAAiBY,EAAwB,IAAOL,GAAe,GAEpG,OACEM,EAACC,IAAAC,YAAU,CAAAX,IAAKA,EAAKG,YAAa,CAAEX,KAAM,CAACF,EAAmBE,QAASe,IACpEK,SAAAC,MAAMC,KAAK,CAAEC,OAAQb,GAAa,CAACc,EAAGC,KACrC,MACMC,EADWD,EAAQ,GAAKhB,EACNlB,GAAesB,EAAOtB,YAAcI,GAAiBkB,EAAOlB,cACpF,OACEsB,MAACE,EAASA,UAAA,CAERR,YAAa,CAAEX,KAAM,CAACF,EAAmBM,mBAAoBY,IAE7DI,SAAAH,EAAAC,IAACS,EAAQA,SAAA,CAACD,KAAMA,EAAME,OAAQF,EAAM3C,MAAO8B,EAAO9B,MAAOC,OAAQ6B,EAAO7B,UAHnE,UAAUyC,WAW3BpB,EAAOwB,YAAc"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{jsx as t}from"react/jsx-runtime";import{forwardRef as i,useMemo as e}from"react";import{Container as r}from"@cleartrip/ct-design-container";import{StarIcon as o}from"@cleartrip/ct-design-icons";import{useTheme as n}from"@cleartrip/ct-design-theme";import{makeStyles as s}from"@cleartrip/ct-design-style-manager";var a;!function(t){t.XS="xs",t.SM="sm",t.MD="md",t.LG="lg",t.XL="xl",t.XXL="xxl"}(a||(a={}));const c=(t,i)=>Object.assign(Object.assign({},((t,i)=>{switch(i){case a.XS:return{width:t.size[2],height:t.size[2]};case a.SM:return{width:t.size[4],height:t.size[4]};case a.MD:return{width:t.size[5],height:t.size[5]};case a.LG:return{width:t.size[6],height:t.size[6]};case a.XL:return{width:t.size[8],height:t.size[8]};case a.XXL:return{width:t.size[10],height:t.size[10]};default:return{width:t.size[4],height:t.size[4]}}})(t,i)),(t=>({activeColor:t.color.text.primary,inActiveColor:t.color.text.tertiary}))(t)),h=s(t=>({root:{flexDirection:"row",padding:null==t?void 0:t.spacing[1],width:"100%"},ratingContainer:{flexDirection:"row"}})),g=i((i,s)=>{const{rating:g=2,maxRating:l=5,size:d=a.LG,activeColor:m,inActiveColor:f,styleConfig:p}=i,z=n(),u=e(()=>c(z,d),[z,d]),{root:w=[],ratingContainer:C=[]}=p||{};return t(r,{ref:s,styleConfig:{root:[h.root,...w]},children:Array.from({length:l},(i,e)=>{const n=e+1<=g?m||u.activeColor:f||u.inActiveColor;return t(r,{styleConfig:{root:[h.ratingContainer,...C]},children:t(o,{fill:n,stroke:n,width:u.width,height:u.height})},`rating_${e}`)})})});g.displayName="Rating";export{g as Rating,a as RatingSize};
|
|
2
2
|
//# sourceMappingURL=ct-design-rating.browser.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ct-design-rating.browser.esm.js","sources":["../packages/components/Rating/src/type.ts","../packages/components/Rating/src/style.ts","../packages/components/Rating/src/Rating.tsx"],"sourcesContent":[null,null,null],"names":["
|
|
1
|
+
{"version":3,"file":"ct-design-rating.browser.esm.js","sources":["../packages/components/Rating/src/type.ts","../packages/components/Rating/src/style.ts","../packages/components/Rating/src/Rating.tsx"],"sourcesContent":[null,null,null],"names":["RatingSize","getRatingTokens","theme","size","Object","assign","XS","width","height","SM","MD","LG","XL","XXL","getRatingSizeTokens","activeColor","color","text","primary","inActiveColor","tertiary","getRatingColorTokens","staticRatingStyles","makeStyles","root","flexDirection","padding","spacing","ratingContainer","Rating","forwardRef","props","ref","rating","maxRating","styleConfig","useTheme","tokens","useMemo","customRootStyles","customRatingContainer","_jsx","Container","children","Array","from","length","_","index","fill","StarIcon","stroke","displayName"],"mappings":"mUAGYA,GAAZ,SAAYA,GACVA,EAAA,GAAA,KACAA,EAAA,GAAA,KACAA,EAAA,GAAA,KACAA,EAAA,GAAA,KACAA,EAAA,GAAA,KACAA,EAAA,IAAA,KACD,CAPD,CAAYA,IAAAA,EAOX,CAAA,ICIM,MAwBMC,EAAkB,CAACC,EAAcC,IAA+DC,OAAAC,OAAAD,OAAAC,OAAA,CAAA,EAxB1E,EAACH,EAAcC,KAChD,OAAQA,GACN,KAAKH,EAAWM,GACd,MAAO,CAAEC,MAAOL,EAAMC,KAAK,GAAIK,OAAQN,EAAMC,KAAK,IACpD,KAAKH,EAAWS,GACd,MAAO,CAAEF,MAAOL,EAAMC,KAAK,GAAIK,OAAQN,EAAMC,KAAK,IACpD,KAAKH,EAAWU,GACd,MAAO,CAAEH,MAAOL,EAAMC,KAAK,GAAIK,OAAQN,EAAMC,KAAK,IACpD,KAAKH,EAAWW,GACd,MAAO,CAAEJ,MAAOL,EAAMC,KAAK,GAAIK,OAAQN,EAAMC,KAAK,IACpD,KAAKH,EAAWY,GACd,MAAO,CAAEL,MAAOL,EAAMC,KAAK,GAAIK,OAAQN,EAAMC,KAAK,IACpD,KAAKH,EAAWa,IACd,MAAO,CAAEN,MAAOL,EAAMC,KAAK,IAAKK,OAAQN,EAAMC,KAAK,KACrD,QACE,MAAO,CAAEI,MAAOL,EAAMC,KAAK,GAAIK,OAAQN,EAAMC,KAAK,MAUnDW,CAAoBZ,EAAOC,IANI,CAACD,IAAqC,CACxEa,YAAab,EAAMc,MAAMC,KAAKC,QAC9BC,cAAejB,EAAMc,MAAMC,KAAKG,WAK7BC,CAAqBnB,IC7BpBoB,EAAqBC,EAAYrB,IAAW,CAChDsB,KAAM,CACJC,cAAe,MACfC,QAASxB,aAAK,EAALA,EAAOyB,QAAQ,GACxBpB,MAAO,QAETqB,gBAAiB,CACfH,cAAe,UAIbI,EAASC,EAAuC,CAACC,EAAOC,KAC5D,MAAMC,OAAEA,EAAS,EAACC,UAAEA,EAAY,EAAC/B,KAAEA,EAAOH,EAAWW,GAAEI,YAAEA,EAAWI,cAAEA,EAAagB,YAAEA,GAAgBJ,EAC/F7B,EAAQkC,IAERC,EAASC,EAAQ,IAAMrC,EAAgBC,EAAOC,GAAO,CAACD,EAAOC,KAE3DqB,KAAMe,EAAmB,GAAIX,gBAAiBY,EAAwB,IAAOL,GAAe,GAEpG,OACEM,EAACC,EAAU,CAAAV,IAAKA,EAAKG,YAAa,CAAEX,KAAM,CAACF,EAAmBE,QAASe,IACpEI,SAAAC,MAAMC,KAAK,CAAEC,OAAQZ,GAAa,CAACa,EAAGC,KACrC,MACMC,EADWD,EAAQ,GAAKf,EACNlB,GAAesB,EAAOtB,YAAcI,GAAiBkB,EAAOlB,cACpF,OACEsB,EAACC,EAAS,CAERP,YAAa,CAAEX,KAAM,CAACF,EAAmBM,mBAAoBY,IAE7DG,SAAAF,EAACS,EAAQ,CAACD,KAAMA,EAAME,OAAQF,EAAM1C,MAAO8B,EAAO9B,MAAOC,OAAQ6B,EAAO7B,UAHnE,UAAUwC,WAW3BnB,EAAOuB,YAAc"}
|
|
@@ -1,106 +1,68 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var tslib = require('tslib');
|
|
4
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
-
var
|
|
4
|
+
var react = require('react');
|
|
6
5
|
var ctDesignContainer = require('@cleartrip/ct-design-container');
|
|
7
6
|
var ctDesignIcons = require('@cleartrip/ct-design-icons');
|
|
7
|
+
var ctDesignTheme = require('@cleartrip/ct-design-theme');
|
|
8
|
+
var ctDesignStyleManager = require('@cleartrip/ct-design-style-manager');
|
|
8
9
|
|
|
9
|
-
exports.
|
|
10
|
-
(function (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
exports.
|
|
18
|
-
(function (StarVariantProps) {
|
|
19
|
-
StarVariantProps["DEFAULT"] = "default";
|
|
20
|
-
StarVariantProps["DISABLED"] = "disabled";
|
|
21
|
-
})(exports.StarVariantProps || (exports.StarVariantProps = {}));
|
|
10
|
+
exports.RatingSize = void 0;
|
|
11
|
+
(function (RatingSize) {
|
|
12
|
+
RatingSize["XS"] = "xs";
|
|
13
|
+
RatingSize["SM"] = "sm";
|
|
14
|
+
RatingSize["MD"] = "md";
|
|
15
|
+
RatingSize["LG"] = "lg";
|
|
16
|
+
RatingSize["XL"] = "xl";
|
|
17
|
+
RatingSize["XXL"] = "xxl";
|
|
18
|
+
})(exports.RatingSize || (exports.RatingSize = {}));
|
|
22
19
|
|
|
23
|
-
|
|
20
|
+
const getRatingSizeTokens = (theme, size) => {
|
|
24
21
|
switch (size) {
|
|
25
|
-
case
|
|
26
|
-
return {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
case
|
|
32
|
-
return {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
width: 16,
|
|
40
|
-
height: 16,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
case 'xl': {
|
|
44
|
-
return {
|
|
45
|
-
width: 18,
|
|
46
|
-
height: 18,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
case 'xxl': {
|
|
50
|
-
return {
|
|
51
|
-
width: 20,
|
|
52
|
-
height: 20,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
22
|
+
case exports.RatingSize.XS:
|
|
23
|
+
return { width: theme.size[2], height: theme.size[2] };
|
|
24
|
+
case exports.RatingSize.SM:
|
|
25
|
+
return { width: theme.size[4], height: theme.size[4] };
|
|
26
|
+
case exports.RatingSize.MD:
|
|
27
|
+
return { width: theme.size[5], height: theme.size[5] };
|
|
28
|
+
case exports.RatingSize.LG:
|
|
29
|
+
return { width: theme.size[6], height: theme.size[6] };
|
|
30
|
+
case exports.RatingSize.XL:
|
|
31
|
+
return { width: theme.size[8], height: theme.size[8] };
|
|
32
|
+
case exports.RatingSize.XXL:
|
|
33
|
+
return { width: theme.size[10], height: theme.size[10] };
|
|
34
|
+
default:
|
|
35
|
+
return { width: theme.size[4], height: theme.size[4] };
|
|
55
36
|
}
|
|
56
37
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
fill: activeColor || theme.color.background.primary,
|
|
63
|
-
stroke: activeColor || theme.color.background.primary,
|
|
64
|
-
width: (_a = getStarSize(size)) === null || _a === void 0 ? void 0 : _a.width,
|
|
65
|
-
height: (_b = getStarSize(size)) === null || _b === void 0 ? void 0 : _b.height,
|
|
66
|
-
cursor: 'default',
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
var getDefaultStarStyles = function (theme, size, activeColor, inActiveColor) {
|
|
70
|
-
var _a, _b;
|
|
71
|
-
return {
|
|
72
|
-
color: activeColor || theme.color.background.primary,
|
|
73
|
-
unfilled: inActiveColor || theme.color.background.grey,
|
|
74
|
-
fill: activeColor || theme.color.background.primary,
|
|
75
|
-
stroke: activeColor || theme.color.background.primary,
|
|
76
|
-
width: (_a = getStarSize(size)) === null || _a === void 0 ? void 0 : _a.width,
|
|
77
|
-
height: (_b = getStarSize(size)) === null || _b === void 0 ? void 0 : _b.height,
|
|
78
|
-
cursor: 'pointer',
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
var getStarStyles = function (_a) {
|
|
82
|
-
var variant = _a.variant, size = _a.size, theme = _a.theme, activeColor = _a.activeColor, inActiveColor = _a.inActiveColor;
|
|
83
|
-
if (variant === exports.StarVariantProps.DISABLED) {
|
|
84
|
-
return getDisabledStarStyles(theme, size, activeColor, inActiveColor);
|
|
85
|
-
}
|
|
86
|
-
return getDefaultStarStyles(theme, size, activeColor, inActiveColor);
|
|
87
|
-
};
|
|
38
|
+
const getRatingColorTokens = (theme) => ({
|
|
39
|
+
activeColor: theme.color.text.primary,
|
|
40
|
+
inActiveColor: theme.color.text.tertiary,
|
|
41
|
+
});
|
|
42
|
+
const getRatingTokens = (theme, size) => (Object.assign(Object.assign({}, getRatingSizeTokens(theme, size)), getRatingColorTokens(theme)));
|
|
88
43
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
};
|
|
44
|
+
const staticRatingStyles = ctDesignStyleManager.makeStyles((theme) => ({
|
|
45
|
+
root: {
|
|
46
|
+
flexDirection: 'row',
|
|
47
|
+
padding: theme === null || theme === void 0 ? void 0 : theme.spacing[1],
|
|
48
|
+
width: '100%',
|
|
49
|
+
},
|
|
50
|
+
ratingContainer: {
|
|
51
|
+
flexDirection: 'row',
|
|
52
|
+
},
|
|
53
|
+
}));
|
|
54
|
+
const Rating = react.forwardRef((props, ref) => {
|
|
55
|
+
const { rating = 2, maxRating = 5, size = exports.RatingSize.LG, activeColor, inActiveColor, styleConfig } = props;
|
|
56
|
+
const theme = ctDesignTheme.useTheme();
|
|
57
|
+
const tokens = react.useMemo(() => getRatingTokens(theme, size), [theme, size]);
|
|
58
|
+
const { root: customRootStyles = [], ratingContainer: customRatingContainer = [] } = styleConfig || {};
|
|
59
|
+
return (jsxRuntime.jsx(ctDesignContainer.Container, { ref: ref, styleConfig: { root: [staticRatingStyles.root, ...customRootStyles] }, children: Array.from({ length: maxRating }, (_, index) => {
|
|
60
|
+
const isActive = index + 1 <= rating;
|
|
61
|
+
const fill = isActive ? activeColor || tokens.activeColor : inActiveColor || tokens.inActiveColor;
|
|
62
|
+
return (jsxRuntime.jsx(ctDesignContainer.Container, { styleConfig: { root: [staticRatingStyles.ratingContainer, ...customRatingContainer] }, children: jsxRuntime.jsx(ctDesignIcons.StarIcon, { fill: fill, stroke: fill, width: tokens.width, height: tokens.height }) }, `rating_${index}`));
|
|
63
|
+
}) }));
|
|
64
|
+
});
|
|
65
|
+
Rating.displayName = 'Rating';
|
|
104
66
|
|
|
105
67
|
exports.Rating = Rating;
|
|
106
68
|
//# sourceMappingURL=ct-design-rating.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ct-design-rating.cjs.js","sources":["../packages/components/Rating/src/type.ts","../packages/components/Rating/src/style.ts","../packages/components/Rating/src/Rating.tsx"],"sourcesContent":[null,null,null],"names":["
|
|
1
|
+
{"version":3,"file":"ct-design-rating.cjs.js","sources":["../packages/components/Rating/src/type.ts","../packages/components/Rating/src/style.ts","../packages/components/Rating/src/Rating.tsx"],"sourcesContent":[null,null,null],"names":["RatingSize","makeStyles","forwardRef","useTheme","useMemo","_jsx","Container","StarIcon"],"mappings":";;;;;;;;;AAGYA,4BAOX;AAPD,CAAA,UAAY,UAAU,EAAA;AACpB,IAAA,UAAA,CAAA,IAAA,CAAA,GAAA,IAAS,CAAA;AACT,IAAA,UAAA,CAAA,IAAA,CAAA,GAAA,IAAS,CAAA;AACT,IAAA,UAAA,CAAA,IAAA,CAAA,GAAA,IAAS,CAAA;AACT,IAAA,UAAA,CAAA,IAAA,CAAA,GAAA,IAAS,CAAA;AACT,IAAA,UAAA,CAAA,IAAA,CAAA,GAAA,IAAS,CAAA;AACT,IAAA,UAAA,CAAA,KAAA,CAAA,GAAA,KAAW,CAAA;AACb,CAAC,EAPWA,kBAAU,KAAVA,kBAAU,GAOrB,EAAA,CAAA,CAAA;;ACIM,MAAM,mBAAmB,GAAG,CAAC,KAAY,EAAE,IAAoB,KAAsB;IAC1F,QAAQ,IAAI;QACV,KAAKA,kBAAU,CAAC,EAAE;AAChB,YAAA,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,C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AC,2BAAS,EAAC,EAAA,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,CAAC,kBAAkB,CAAC,IAAI,EAAE,GAAG,gBAAgB,CAAC,EAAE,EACvF,QAAA,EAAA,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,KAAI;AAC9C,YAAA,MAAM,QAAQ,GAAG,KAAK,GAAG,CAAC,IAAI,MAAM,CAAC;AACrC,YAAA,MAAM,IAAI,GAAG,QAAQ,GAAG,WAAW,IAAI,MAAM,CAAC,WAAW,GAAG,aAAa,IAAI,MAAM,CAAC,aAAa,CAAC;YAClG,QACED,eAACC,2BAAS,EAAA,EAER,WAAW,EAAE,EAAE,IAAI,EAAE,CAAC,kBAAkB,CAAC,eAAe,EAAE,GAAG,qBAAqB,CAAC,EAAE,EAErF,QAAA,EAAAD,cAAA,CAACE,sBAAQ,EAAA,EAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAI,CAAA,EAAA,EAH7E,UAAU,KAAK,CAAA,CAAE,CAIZ,EACZ;SACH,CAAC,EACQ,CAAA,EACZ;AACJ,CAAC,EAAE;AAEH,MAAM,CAAC,WAAW,GAAG,QAAQ;;;;"}
|
|
@@ -1,104 +1,66 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
1
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import {
|
|
2
|
+
import { forwardRef, useMemo } from 'react';
|
|
4
3
|
import { Container } from '@cleartrip/ct-design-container';
|
|
5
4
|
import { StarIcon } from '@cleartrip/ct-design-icons';
|
|
5
|
+
import { useTheme } from '@cleartrip/ct-design-theme';
|
|
6
|
+
import { makeStyles } from '@cleartrip/ct-design-style-manager';
|
|
6
7
|
|
|
7
|
-
var
|
|
8
|
-
(function (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
(function (StarVariantProps) {
|
|
17
|
-
StarVariantProps["DEFAULT"] = "default";
|
|
18
|
-
StarVariantProps["DISABLED"] = "disabled";
|
|
19
|
-
})(StarVariantProps || (StarVariantProps = {}));
|
|
8
|
+
var RatingSize;
|
|
9
|
+
(function (RatingSize) {
|
|
10
|
+
RatingSize["XS"] = "xs";
|
|
11
|
+
RatingSize["SM"] = "sm";
|
|
12
|
+
RatingSize["MD"] = "md";
|
|
13
|
+
RatingSize["LG"] = "lg";
|
|
14
|
+
RatingSize["XL"] = "xl";
|
|
15
|
+
RatingSize["XXL"] = "xxl";
|
|
16
|
+
})(RatingSize || (RatingSize = {}));
|
|
20
17
|
|
|
21
|
-
|
|
18
|
+
const getRatingSizeTokens = (theme, size) => {
|
|
22
19
|
switch (size) {
|
|
23
|
-
case
|
|
24
|
-
return {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
case
|
|
30
|
-
return {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
width: 16,
|
|
38
|
-
height: 16,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
case 'xl': {
|
|
42
|
-
return {
|
|
43
|
-
width: 18,
|
|
44
|
-
height: 18,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
case 'xxl': {
|
|
48
|
-
return {
|
|
49
|
-
width: 20,
|
|
50
|
-
height: 20,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
20
|
+
case RatingSize.XS:
|
|
21
|
+
return { width: theme.size[2], height: theme.size[2] };
|
|
22
|
+
case RatingSize.SM:
|
|
23
|
+
return { width: theme.size[4], height: theme.size[4] };
|
|
24
|
+
case RatingSize.MD:
|
|
25
|
+
return { width: theme.size[5], height: theme.size[5] };
|
|
26
|
+
case RatingSize.LG:
|
|
27
|
+
return { width: theme.size[6], height: theme.size[6] };
|
|
28
|
+
case RatingSize.XL:
|
|
29
|
+
return { width: theme.size[8], height: theme.size[8] };
|
|
30
|
+
case RatingSize.XXL:
|
|
31
|
+
return { width: theme.size[10], height: theme.size[10] };
|
|
32
|
+
default:
|
|
33
|
+
return { width: theme.size[4], height: theme.size[4] };
|
|
53
34
|
}
|
|
54
35
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
fill: activeColor || theme.color.background.primary,
|
|
61
|
-
stroke: activeColor || theme.color.background.primary,
|
|
62
|
-
width: (_a = getStarSize(size)) === null || _a === void 0 ? void 0 : _a.width,
|
|
63
|
-
height: (_b = getStarSize(size)) === null || _b === void 0 ? void 0 : _b.height,
|
|
64
|
-
cursor: 'default',
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
var getDefaultStarStyles = function (theme, size, activeColor, inActiveColor) {
|
|
68
|
-
var _a, _b;
|
|
69
|
-
return {
|
|
70
|
-
color: activeColor || theme.color.background.primary,
|
|
71
|
-
unfilled: inActiveColor || theme.color.background.grey,
|
|
72
|
-
fill: activeColor || theme.color.background.primary,
|
|
73
|
-
stroke: activeColor || theme.color.background.primary,
|
|
74
|
-
width: (_a = getStarSize(size)) === null || _a === void 0 ? void 0 : _a.width,
|
|
75
|
-
height: (_b = getStarSize(size)) === null || _b === void 0 ? void 0 : _b.height,
|
|
76
|
-
cursor: 'pointer',
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
var getStarStyles = function (_a) {
|
|
80
|
-
var variant = _a.variant, size = _a.size, theme = _a.theme, activeColor = _a.activeColor, inActiveColor = _a.inActiveColor;
|
|
81
|
-
if (variant === StarVariantProps.DISABLED) {
|
|
82
|
-
return getDisabledStarStyles(theme, size, activeColor, inActiveColor);
|
|
83
|
-
}
|
|
84
|
-
return getDefaultStarStyles(theme, size, activeColor, inActiveColor);
|
|
85
|
-
};
|
|
36
|
+
const getRatingColorTokens = (theme) => ({
|
|
37
|
+
activeColor: theme.color.text.primary,
|
|
38
|
+
inActiveColor: theme.color.text.tertiary,
|
|
39
|
+
});
|
|
40
|
+
const getRatingTokens = (theme, size) => (Object.assign(Object.assign({}, getRatingSizeTokens(theme, size)), getRatingColorTokens(theme)));
|
|
86
41
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
};
|
|
42
|
+
const staticRatingStyles = makeStyles((theme) => ({
|
|
43
|
+
root: {
|
|
44
|
+
flexDirection: 'row',
|
|
45
|
+
padding: theme === null || theme === void 0 ? void 0 : theme.spacing[1],
|
|
46
|
+
width: '100%',
|
|
47
|
+
},
|
|
48
|
+
ratingContainer: {
|
|
49
|
+
flexDirection: 'row',
|
|
50
|
+
},
|
|
51
|
+
}));
|
|
52
|
+
const Rating = forwardRef((props, ref) => {
|
|
53
|
+
const { rating = 2, maxRating = 5, size = RatingSize.LG, activeColor, inActiveColor, styleConfig } = props;
|
|
54
|
+
const theme = useTheme();
|
|
55
|
+
const tokens = useMemo(() => getRatingTokens(theme, size), [theme, size]);
|
|
56
|
+
const { root: customRootStyles = [], ratingContainer: customRatingContainer = [] } = styleConfig || {};
|
|
57
|
+
return (jsx(Container, { ref: ref, styleConfig: { root: [staticRatingStyles.root, ...customRootStyles] }, children: Array.from({ length: maxRating }, (_, index) => {
|
|
58
|
+
const isActive = index + 1 <= rating;
|
|
59
|
+
const fill = isActive ? activeColor || tokens.activeColor : inActiveColor || tokens.inActiveColor;
|
|
60
|
+
return (jsx(Container, { styleConfig: { root: [staticRatingStyles.ratingContainer, ...customRatingContainer] }, children: jsx(StarIcon, { fill: fill, stroke: fill, width: tokens.width, height: tokens.height }) }, `rating_${index}`));
|
|
61
|
+
}) }));
|
|
62
|
+
});
|
|
63
|
+
Rating.displayName = 'Rating';
|
|
102
64
|
|
|
103
|
-
export { Rating,
|
|
65
|
+
export { Rating, RatingSize };
|
|
104
66
|
//# sourceMappingURL=ct-design-rating.esm.js.map
|