@cleartrip/ct-design-dropdown 4.0.0 → 5.0.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 +63 -0
- package/dist/Dropdown.d.ts +0 -1
- package/dist/Dropdown.d.ts.map +1 -1
- package/dist/Dropdown.native.d.ts +4 -0
- package/dist/Dropdown.native.d.ts.map +1 -0
- package/dist/ct-design-dropdown.browser.cjs.js +1 -1
- package/dist/ct-design-dropdown.browser.cjs.js.map +1 -1
- package/dist/ct-design-dropdown.browser.esm.js +1 -1
- package/dist/ct-design-dropdown.browser.esm.js.map +1 -1
- package/dist/ct-design-dropdown.cjs.js +105 -108
- package/dist/ct-design-dropdown.cjs.js.map +1 -1
- package/dist/ct-design-dropdown.esm.js +109 -107
- package/dist/ct-design-dropdown.esm.js.map +1 -1
- package/dist/ct-design-dropdown.umd.js +107 -146
- package/dist/ct-design-dropdown.umd.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.native.d.ts +3 -0
- package/dist/index.native.d.ts.map +1 -0
- package/dist/style.d.ts +41 -5
- package/dist/style.d.ts.map +1 -1
- package/dist/type.d.ts +22 -28
- package/dist/type.d.ts.map +1 -1
- package/package.json +22 -17
- package/src/Dropdown.native.tsx +236 -0
- package/src/Dropdown.tsx +221 -0
- package/src/index.native.ts +2 -0
- package/src/index.ts +2 -0
- package/src/style.ts +51 -0
- package/src/type.ts +70 -0
- package/dist/DropdownOption/DropdownOption.d.ts +0 -5
- package/dist/DropdownOption/DropdownOption.d.ts.map +0 -1
- package/dist/DropdownOption/StyledDropdownOption/StyledDropdownOption.d.ts +0 -8
- package/dist/DropdownOption/StyledDropdownOption/StyledDropdownOption.d.ts.map +0 -1
- package/dist/DropdownOption/index.d.ts +0 -2
- package/dist/DropdownOption/index.d.ts.map +0 -1
- package/dist/DropdownOption/type.d.ts +0 -20
- package/dist/DropdownOption/type.d.ts.map +0 -1
- package/dist/StyledDropdown/StyledDropdown.d.ts +0 -7
- package/dist/StyledDropdown/StyledDropdown.d.ts.map +0 -1
- package/dist/StyledDropdown/index.d.ts +0 -2
- package/dist/StyledDropdown/index.d.ts.map +0 -1
- package/dist/StyledDropdown/style.d.ts +0 -7
- package/dist/StyledDropdown/style.d.ts.map +0 -1
- package/dist/StyledDropdown/type.d.ts +0 -9
- package/dist/StyledDropdown/type.d.ts.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Dropdown
|
|
2
|
+
|
|
3
|
+
A dropdown menu component for selecting from a list of options.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @cleartrip/ct-design-dropdown
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @cleartrip/ct-design-dropdown
|
|
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 { Dropdown } from '@cleartrip/ct-design-dropdown';
|
|
36
|
+
|
|
37
|
+
function Example() {
|
|
38
|
+
return (
|
|
39
|
+
<Dropdown>
|
|
40
|
+
{/* Basic usage */}
|
|
41
|
+
</Dropdown>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Accessibility
|
|
49
|
+
|
|
50
|
+
- The component follows accessibility best practices
|
|
51
|
+
- Ensure proper ARIA attributes are provided where needed
|
|
52
|
+
- Test with screen readers to ensure usability
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Migration
|
|
57
|
+
|
|
58
|
+
If migrating from a previous version:
|
|
59
|
+
|
|
60
|
+
```diff
|
|
61
|
+
- import { Dropdown } from 'yagami/core/components';
|
|
62
|
+
+ import { Dropdown } from '@cleartrip/ct-design-dropdown';
|
|
63
|
+
```
|
package/dist/Dropdown.d.ts
CHANGED
package/dist/Dropdown.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dropdown.d.ts","sourceRoot":"","sources":["../packages/components/Dropdown/src/Dropdown.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Dropdown.d.ts","sourceRoot":"","sources":["../packages/components/Dropdown/src/Dropdown.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAQ,MAAM,QAAQ,CAAC;AA2E7C,QAAA,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CA8HrC,CAAC;AAYF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dropdown.native.d.ts","sourceRoot":"","sources":["../packages/components/Dropdown/src/Dropdown.native.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAQ,MAAM,QAAQ,CAAC;AA8C7C,QAAA,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAmLrC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),o=require("react"),t=require("@cleartrip/ct-design-typography"),r=require("@cleartrip/ct-design-style-manager"),n=require("@cleartrip/ct-design-icons");const i=e=>({flex:1,height:e,justifyContent:"center",paddingHorizontal:12}),a=r.makeStyles(()=>({root:{width:"100%",backgroundColor:"#fff",position:"relative"},dropDownItemListContainer:{width:"100%",maxHeight:240,borderRadius:5,position:"absolute",overflow:"hidden",shadowColor:"#000",shadowOffset:{width:0,height:1},shadowOpacity:.22,shadowRadius:2.22,elevation:3,backgroundColor:"#fff"},dropDownItemContainer:{width:"100%",justifyContent:"center",paddingHorizontal:16,paddingVertical:12},chevronDownContainer:{height:24,left:3,paddingRight:12},scrollArea:{maxHeight:240,overflowY:"auto"}})),l=({item:o,index:n,isSelected:i,dropdownItem:a,onSelect:l,customItemContainer:s=[],customItemTextContainer:d={}})=>{const c=r.useStyles(()=>({root:{backgroundColor:i?"#1a1a1a":"#fff",cursor:"pointer",width:"100%",justifyContent:"center",paddingHorizontal:16,paddingVertical:12}}),[i]),p=r.useWebMergeStyles([c.root,...s],[c.root,s]);return e.jsx("div",{className:p,onClick:()=>l(o,n),children:e.jsx(t.Typography,{styleConfig:d,variant:t.TypographyVariant.HM4,color:i?t.TypographyColor.NEUTRAL:t.TypographyColor.PRIMARY,children:a})})};exports.Dropdown=({placeHolder:s,itemList:d,height:c=40,styleConfig:p={},dropDownValue:u,defaultSelectedIndex:h,onItemSelect:g,renderItem:m,showDropDownListOnTop:C=!0})=>{const{placeHolderContainer:y=[],placeHolderTextContainer:f=[],dropDownItemListContainer:w=[],dropDownItemContainer:x=[],dropDownItemTextContainer:v={}}=p,I=o.useRef(null),[b,S]=o.useState(!1),[T,D]=o.useState(null!=h?h:-1);o.useEffect(()=>{if(!b)return;const e=e=>{I.current&&!I.current.contains(e.target)&&S(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[b]);const H=r.useStyles(e=>({placeHolderContainer:{width:"100%",height:c,backgroundColor:"#fff",borderRadius:5,flexDirection:"row",alignItems:"center",borderColor:b?e.color.border.primary:"#e0e0e0",borderWidth:1},placeHolderTextContainer:i(c)}),[b,c]),j=(e,o)=>{D(o),null==g||g(e,o),S(!1)},M=C,R=r.useWebMergeStyles([a.root],[]),L=r.useWebMergeStyles([H.placeHolderContainer,...y],[H.placeHolderContainer,y]),k=r.useWebMergeStyles([H.placeHolderTextContainer],[H.placeHolderTextContainer]),N=r.useWebMergeStyles([a.chevronDownContainer],[]),W=M?{bottom:c}:{top:c},A=r.useWebMergeStyles([a.dropDownItemListContainer,W,a.scrollArea,...w],[M,c,w]);return e.jsxs("div",{ref:I,className:R,children:[e.jsxs("div",{className:L,onClick:()=>S(e=>!e),children:[e.jsx("div",{className:k,children:e.jsx(t.Typography,{color:u.length>0?t.TypographyColor.PRIMARY:t.TypographyColor.DISABLED,lineClamp:1,styleConfig:{root:f},variant:t.TypographyVariant.HM4,children:u.length>0?u:s})}),e.jsx("div",{className:N,children:e.jsx(n.ChevronDown,{})})]}),b&&e.jsx("div",{className:A,children:d.map((o,t)=>{const r=(null==m?void 0:m(o,t))||(null==o?void 0:o.label),n=t===T;return e.jsx(l,{item:o,index:t,isSelected:n,dropdownItem:r,onSelect:j,customItemContainer:x,customItemTextContainer:v},`${o.value}-${t}`)})})]})};
|
|
2
2
|
//# sourceMappingURL=ct-design-dropdown.browser.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ct-design-dropdown.browser.cjs.js","sources":["../packages/components/Dropdown/src/
|
|
1
|
+
{"version":3,"file":"ct-design-dropdown.browser.cjs.js","sources":["../packages/components/Dropdown/src/style.ts","../packages/components/Dropdown/src/Dropdown.tsx"],"sourcesContent":[null,null],"names":["getPlaceHolderTextContainerStyles","height","flex","justifyContent","paddingHorizontal","staticStyles","makeStyles","root","width","backgroundColor","position","dropDownItemListContainer","maxHeight","borderRadius","overflow","shadowColor","shadowOffset","shadowOpacity","shadowRadius","elevation","dropDownItemContainer","paddingVertical","chevronDownContainer","left","paddingRight","scrollArea","overflowY","DropdownListItem","item","index","isSelected","dropdownItem","onSelect","customItemContainer","customItemTextContainer","itemDynamicStyles","useStyles","cursor","mergedItemClassName","useWebMergeStyles","_jsx","className","onClick","children","Typography","styleConfig","variant","TypographyVariant","HM4","color","TypographyColor","NEUTRAL","PRIMARY","placeHolder","itemList","dropDownValue","defaultSelectedIndex","onItemSelect","renderItem","showDropDownListOnTop","placeHolderContainer","customPlaceHolderContainer","placeHolderTextContainer","customPlaceHolderTextContainer","customDropDownItemListContainer","customDropDownItemContainer","dropDownItemTextContainer","rootRef","useRef","focus","setFocus","useState","singleSelectIndex","setSingleSelectIndex","useEffect","handleOutside","event","current","contains","target","document","addEventListener","removeEventListener","dynamicStyles","theme","flexDirection","alignItems","borderColor","border","primary","borderWidth","singleSelectClickHandler","isShownOnTop","mergedRootClassName","mergedPlaceHolderClassName","mergedPlaceHolderTextClassName","mergedChevronClassName","listPositionStyle","bottom","top","mergedListClassName","_jsxs","ref","state","length","DISABLED","lineClamp","jsx","ChevronDown","map","label","value"],"mappings":"wMA4BO,MAiBMA,EAAqCC,IAAoB,CACpEC,KAAM,EACND,SACAE,eAAgB,SAChBC,kBAAmB,KCxCfC,EAAeC,EAAUA,WAAC,KAAO,CACrCC,KAAM,CACJC,MAAO,OACPC,gBAAiB,OACjBC,SAAU,YAEZC,0BAA2B,CACzBH,MAAO,OACPI,UAAW,IACXC,aAAc,EACdH,SAAU,WACVI,SAAU,SACVC,YAAa,OACbC,aAAc,CAAER,MAAO,EAAGP,OAAQ,GAClCgB,cAAe,IACfC,aAAc,KACdC,UAAW,EACXV,gBAAiB,QAEnBW,sBAAuB,CACrBZ,MAAO,OACPL,eAAgB,SAChBC,kBAAmB,GACnBiB,gBAAiB,IAEnBC,qBDN8C,CAC9CrB,OAAQ,GACRsB,KAAM,EACNC,aAAc,ICIdC,WAAY,CACVb,UAAW,IACXc,UAAW,WAITC,EAAoD,EACxDC,OACAC,QACAC,aACAC,eACAC,WACAC,sBAAsB,GACtBC,0BAA0B,CAAE,MAE5B,MAAMC,EAAoBC,EAAAA,UACxB,KAAO,CACL7B,KAAM,CACJE,gBAAiBqB,EAAa,UAAY,OAC1CO,OAAQ,UACR7B,MAAO,OACPL,eAAgB,SAChBC,kBAAmB,GACn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OA,EACPC,WAAYA,EACZC,aAAcA,EACdC,SAAU2D,EACV1D,oBAAqBgC,EACrB/B,wBAAyBgC,GAPpB,GAAGtC,EAAKmF,SAASlF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{jsxs as e,jsx as o}from"react/jsx-runtime";import{useRef as t,useState as r,useEffect as n}from"react";import{Typography as i,TypographyColor as a,TypographyVariant as l}from"@cleartrip/ct-design-typography";import{makeStyles as d,useStyles as c,useWebMergeStyles as s}from"@cleartrip/ct-design-style-manager";import{ChevronDown as m}from"@cleartrip/ct-design-icons";const p=e=>({flex:1,height:e,justifyContent:"center",paddingHorizontal:12}),h=d(()=>({root:{width:"100%",backgroundColor:"#fff",position:"relative"},dropDownItemListContainer:{width:"100%",maxHeight:240,borderRadius:5,position:"absolute",overflow:"hidden",shadowColor:"#000",shadowOffset:{width:0,height:1},shadowOpacity:.22,shadowRadius:2.22,elevation:3,backgroundColor:"#fff"},dropDownItemContainer:{width:"100%",justifyContent:"center",paddingHorizontal:16,paddingVertical:12},chevronDownContainer:{height:24,left:3,paddingRight:12},scrollArea:{maxHeight:240,overflowY:"auto"}})),u=({item:e,index:t,isSelected:r,dropdownItem:n,onSelect:d,customItemContainer:m=[],customItemTextContainer:p={}})=>{const h=c(()=>({root:{backgroundColor:r?"#1a1a1a":"#fff",cursor:"pointer",width:"100%",justifyContent:"center",paddingHorizontal:16,paddingVertical:12}}),[r]),u=s([h.root,...m],[h.root,m]);return o("div",{className:u,onClick:()=>d(e,t),children:o(i,{styleConfig:p,variant:l.HM4,color:r?a.NEUTRAL:a.PRIMARY,children:n})})},C=({placeHolder:d,itemList:C,height:f=40,styleConfig:g={},dropDownValue:w,defaultSelectedIndex:v,onItemSelect:I,renderItem:x,showDropDownListOnTop:H=!0})=>{const{placeHolderContainer:D=[],placeHolderTextContainer:b=[],dropDownItemListContainer:y=[],dropDownItemContainer:L=[],dropDownItemTextContainer:R={}}=g,T=t(null),[N,S]=r(!1),[k,A]=r(null!=v?v:-1);n(()=>{if(!N)return;const e=e=>{T.current&&!T.current.contains(e.target)&&S(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[N]);const j=c(e=>({placeHolderContainer:{width:"100%",height:f,backgroundColor:"#fff",borderRadius:5,flexDirection:"row",alignItems:"center",borderColor:N?e.color.border.primary:"#e0e0e0",borderWidth:1},placeHolderTextContainer:p(f)}),[N,f]),E=(e,o)=>{A(o),null==I||I(e,o),S(!1)},M=H,z=s([h.root],[]),O=s([j.placeHolderContainer,...D],[j.placeHolderContainer,D]),V=s([j.placeHolderTextContainer],[j.placeHolderTextContainer]),Y=s([h.chevronDownContainer],[]),P=M?{bottom:f}:{top:f},$=s([h.dropDownItemListContainer,P,h.scrollArea,...y],[M,f,y]);return e("div",{ref:T,className:z,children:[e("div",{className:O,onClick:()=>S(e=>!e),children:[o("div",{className:V,children:o(i,{color:w.length>0?a.PRIMARY:a.DISABLED,lineClamp:1,styleConfig:{root:b},variant:l.HM4,children:w.length>0?w:d})}),o("div",{className:Y,children:o(m,{})})]}),N&&o("div",{className:$,children:C.map((e,t)=>{const r=(null==x?void 0:x(e,t))||(null==e?void 0:e.label);return o(u,{item:e,index:t,isSelected:t===k,dropdownItem:r,onSelect:E,customItemContainer:L,customItemTextContainer:R},`${e.value}-${t}`)})})]})};export{C as Dropdown};
|
|
2
2
|
//# sourceMappingURL=ct-design-dropdown.browser.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ct-design-dropdown.browser.esm.js","sources":["../packages/components/Dropdown/src/
|
|
1
|
+
{"version":3,"file":"ct-design-dropdown.browser.esm.js","sources":["../packages/components/Dropdown/src/style.ts","../packages/components/Dropdown/src/Dropdown.tsx"],"sourcesContent":[null,null],"names":["getPlaceHolderTextContainerStyles","height","flex","justifyContent","paddingHorizontal","staticStyles","makeStyles","root","width","backgroundColor","position","dropDownItemListContainer","maxHeight","borderRadius","overflow","shadowColor","shadowOffset","shadowOpacity","shadowRadius","elevation","dropDownItemContainer","paddingVertical","chevronDownContainer","left","paddingRight","scrollArea","overflowY","DropdownListItem","item","index","isSelected","dropdownItem","onSelect","customItemContainer","customItemTextContainer","itemDynamicStyles","useStyles","cursor","mergedItemClassName","useWebMergeStyles","_jsx","className","onClick","children","Typography","styleConfig","variant","TypographyVariant","HM4","color","TypographyColor","NEUTRAL","PRIMARY","Dropdown","placeHolder","itemList","dropDownValue","defaultSelectedIndex","onItemSelect","renderItem","showDropDownListOnTop","placeHolderContainer","customPlaceHolderContainer","placeHolderTextContainer","customPlaceHolderTextContainer","customDropDownItemListContainer","customDropDownItemContainer","dropDownItemTextContainer","rootRef","useRef","focus","setFocus","useState","singleSelectIndex","setSingleSelectIndex","useEffect","handleOutside","event","current","contains","target","document","addEventListener","removeEventListener","dynamicStyles","theme","flexDirection","alignItems","borderColor","border","primary","borderWidth","singleSelectClickHandler","isShownOnTop","mergedRootClassName","mergedPlaceHolderClassName","mergedPlaceHolderTextClassName","mergedChevronClassName","listPositionStyle","bottom","top","mergedListClassName","_jsxs","ref","state","length","DISABLED","lineClamp","ChevronDown","map","label","value"],"mappings":"sXA4BO,MAiBMA,EAAqCC,IAAoB,CACpEC,KAAM,EACND,SACAE,eAAgB,SAChBC,kBAAmB,KCxCfC,EAAeC,EAAW,KAAO,CACrCC,KAAM,CACJC,MAAO,OACPC,gBAAiB,OACjBC,SAAU,YAEZC,0BAA2B,CACzBH,MAAO,OACPI,UAAW,IACXC,aAAc,EACdH,SAAU,WACVI,SAAU,SACVC,YAAa,OACbC,aAAc,CAAER,MAAO,EAAGP,OAAQ,GAClCgB,cAAe,IACfC,aAAc,KACdC,UAAW,EACXV,gBAAiB,QAEnBW,sBAAuB,CACrBZ,MAAO,OACPL,eAAgB,SAChBC,kBAAmB,GACnBiB,gBAAiB,IAEnBC,qBDN8C,CAC9CrB,OAAQ,GACRsB,KAAM,EACNC,aAAc,ICIdC,WAAY,CACVb,UAAW,IACXc,UAAW,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,EACNC,MAAOA,EACPC,WANeD,IAAU4C,EAOzB1C,aAAcA,EACdC,SAAU4D,EACV3D,oBAAqBiC,EACrBhC,wBAAyBiC,GAPpB,GAAGvC,EAAKmF,SAASlF"}
|
|
@@ -1,123 +1,120 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var tslib = require('tslib');
|
|
4
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
-
var ctDesignContainer = require('@cleartrip/ct-design-container');
|
|
6
|
-
var ctDesignCheckbox = require('@cleartrip/ct-design-checkbox');
|
|
7
|
-
var styled = require('styled-components');
|
|
8
|
-
var ctDesignTheme = require('@cleartrip/ct-design-theme');
|
|
9
4
|
var react = require('react');
|
|
10
5
|
var ctDesignTypography = require('@cleartrip/ct-design-typography');
|
|
11
|
-
var
|
|
12
|
-
var
|
|
6
|
+
var ctDesignStyleManager = require('@cleartrip/ct-design-style-manager');
|
|
7
|
+
var ctDesignIcons = require('@cleartrip/ct-design-icons');
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
exports.DropdownVarient = void 0;
|
|
20
|
-
(function (DropdownVarient) {
|
|
21
|
-
DropdownVarient["FLAT"] = "FLAT";
|
|
22
|
-
DropdownVarient["ROUND"] = "ROUND";
|
|
23
|
-
DropdownVarient["BYLINE"] = "BYLINE";
|
|
24
|
-
DropdownVarient["BYLINE_SIDE"] = "BYLINE_SIDE";
|
|
25
|
-
})(exports.DropdownVarient || (exports.DropdownVarient = {}));
|
|
26
|
-
|
|
27
|
-
var getStyledDropdownStyles = function (_a) {
|
|
28
|
-
var backgroundColor = _a.backgroundColor, width = _a.width, theme = _a.theme, varient = _a.varient, height = _a.height;
|
|
29
|
-
return {
|
|
30
|
-
backgroundColor: backgroundColor,
|
|
31
|
-
width: width,
|
|
32
|
-
padding: varient === exports.DropdownVarient.ROUND ? theme.spacing[2] : 0,
|
|
33
|
-
boxShadow: theme.elevation.bottomE2,
|
|
34
|
-
maxHeight: height,
|
|
35
|
-
overflow: 'auto',
|
|
36
|
-
borderRadius: theme.border.radius[12],
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
var StyledDropdown = styled__default.default.div(function (_a) {
|
|
41
|
-
var theme = _a.theme, backgroundColor = _a.backgroundColor, width = _a.width, varient = _a.varient, height = _a.height, _b = _a.css, css = _b === void 0 ? {} : _b;
|
|
42
|
-
return (tslib.__assign(tslib.__assign({}, getStyledDropdownStyles({ theme: theme, backgroundColor: backgroundColor, width: width, varient: varient, height: height })), css));
|
|
9
|
+
const getChevronContainerStyles = () => ({
|
|
10
|
+
height: 24,
|
|
11
|
+
left: 3,
|
|
12
|
+
paddingRight: 12,
|
|
43
13
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
var getDropdownStyles = function (_a) {
|
|
52
|
-
var theme = _a.theme, width = _a.width;
|
|
53
|
-
return tslib.__assign({}, getDefaultDropdownStyles(theme, width));
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
var StyledDropdownOption = styled__default.default.div(templateObject_2 || (templateObject_2 = tslib.__makeTemplateObject(["\n\t&:hover {\n\t\tbackground-color: ", ";\n\t\tborder-radius: ", ";\n\t}\n\tbackground-color: ", ";\n\tcolor: ", ";\n\tpadding-top: 4px;\n\tpadding-bottom: 4px;\n\t", "\n"], ["\n\t&:hover {\n\t\tbackground-color: ", ";\n\t\tborder-radius: ", ";\n\t}\n\tbackground-color: ", ";\n\tcolor: ", ";\n\tpadding-top: 4px;\n\tpadding-bottom: 4px;\n\t", "\n"])), function (_a) {
|
|
57
|
-
var isSelected = _a.isSelected, varient = _a.varient, theme = _a.theme;
|
|
58
|
-
return isSelected && [exports.DropdownVarient.FLAT, exports.DropdownVarient.BYLINE].includes(varient)
|
|
59
|
-
? theme.color.background.primary
|
|
60
|
-
: theme.color.chip.selectedPrimaryBg;
|
|
61
|
-
}, function (_a) {
|
|
62
|
-
var varient = _a.varient;
|
|
63
|
-
return (varient === exports.DropdownVarient.ROUND ? '4px' : '');
|
|
64
|
-
}, function (_a) {
|
|
65
|
-
var isSelected = _a.isSelected, varient = _a.varient, theme = _a.theme;
|
|
66
|
-
return isSelected && [exports.DropdownVarient.FLAT, exports.DropdownVarient.BYLINE].includes(varient)
|
|
67
|
-
? theme.color.background.primary
|
|
68
|
-
: '';
|
|
69
|
-
}, function (props) { return (props.isSelected ? ctDesignTokens.colors.neutral100 : ''); }, function (_a) {
|
|
70
|
-
var css = _a.css;
|
|
71
|
-
return css && styled.css(templateObject_1 || (templateObject_1 = tslib.__makeTemplateObject(["\n\t", "\n "], ["\n\t", "\n "])), css);
|
|
14
|
+
const getPlaceHolderTextContainerStyles = (height) => ({
|
|
15
|
+
flex: 1,
|
|
16
|
+
height,
|
|
17
|
+
justifyContent: 'center',
|
|
18
|
+
paddingHorizontal: 12,
|
|
72
19
|
});
|
|
73
|
-
var templateObject_1, templateObject_2;
|
|
74
20
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
21
|
+
const staticStyles = ctDesignStyleManager.makeStyles(() => ({
|
|
22
|
+
root: {
|
|
23
|
+
width: '100%',
|
|
24
|
+
backgroundColor: '#fff',
|
|
25
|
+
position: 'relative',
|
|
26
|
+
},
|
|
27
|
+
dropDownItemListContainer: {
|
|
28
|
+
width: '100%',
|
|
29
|
+
maxHeight: 240,
|
|
30
|
+
borderRadius: 5,
|
|
31
|
+
position: 'absolute',
|
|
32
|
+
overflow: 'hidden',
|
|
33
|
+
shadowColor: '#000',
|
|
34
|
+
shadowOffset: { width: 0, height: 1 },
|
|
35
|
+
shadowOpacity: 0.22,
|
|
36
|
+
shadowRadius: 2.22,
|
|
37
|
+
elevation: 3,
|
|
38
|
+
backgroundColor: '#fff',
|
|
39
|
+
},
|
|
40
|
+
dropDownItemContainer: {
|
|
41
|
+
width: '100%',
|
|
42
|
+
justifyContent: 'center',
|
|
43
|
+
paddingHorizontal: 16,
|
|
44
|
+
paddingVertical: 12,
|
|
45
|
+
},
|
|
46
|
+
chevronDownContainer: getChevronContainerStyles(),
|
|
47
|
+
scrollArea: {
|
|
48
|
+
maxHeight: 240,
|
|
49
|
+
overflowY: 'auto',
|
|
50
|
+
},
|
|
51
|
+
}));
|
|
52
|
+
const DropdownListItem = ({ item, index, isSelected, dropdownItem, onSelect, customItemContainer = [], customItemTextContainer = {}, }) => {
|
|
53
|
+
const itemDynamicStyles = ctDesignStyleManager.useStyles(() => ({
|
|
54
|
+
root: {
|
|
55
|
+
backgroundColor: isSelected ? '#1a1a1a' : '#fff',
|
|
56
|
+
cursor: 'pointer',
|
|
57
|
+
width: '100%',
|
|
58
|
+
justifyContent: 'center',
|
|
59
|
+
paddingHorizontal: 16,
|
|
60
|
+
paddingVertical: 12,
|
|
61
|
+
},
|
|
62
|
+
}), [isSelected]);
|
|
63
|
+
const mergedItemClassName = ctDesignStyleManager.useWebMergeStyles([itemDynamicStyles.root, ...customItemContainer], [itemDynamicStyles.root, customItemContainer]);
|
|
64
|
+
return (jsxRuntime.jsx("div", { className: mergedItemClassName, onClick: () => onSelect(item, index), children: jsxRuntime.jsx(ctDesignTypography.Typography, { styleConfig: customItemTextContainer, variant: ctDesignTypography.TypographyVariant.HM4, color: isSelected ? ctDesignTypography.TypographyColor.NEUTRAL : ctDesignTypography.TypographyColor.PRIMARY, children: dropdownItem }) }));
|
|
88
65
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (!option)
|
|
102
|
-
return null;
|
|
103
|
-
var key = option.key, label = option.label, customColor = option.customColor, subLabel = option.subLabel;
|
|
104
|
-
var isSelected = Array.isArray(selectedOption) ? selectedOption.includes(key) : key === selectedOption;
|
|
105
|
-
var setKey = function () {
|
|
106
|
-
onClick === null || onClick === void 0 ? void 0 : onClick(key, isSelected);
|
|
66
|
+
const Dropdown = ({ placeHolder, itemList, height = 40, styleConfig = {}, dropDownValue, defaultSelectedIndex, onItemSelect, renderItem, showDropDownListOnTop = true, }) => {
|
|
67
|
+
const { placeHolderContainer: customPlaceHolderContainer = [], placeHolderTextContainer: customPlaceHolderTextContainer = [], dropDownItemListContainer: customDropDownItemListContainer = [], dropDownItemContainer: customDropDownItemContainer = [], dropDownItemTextContainer = {}, } = styleConfig;
|
|
68
|
+
const rootRef = react.useRef(null);
|
|
69
|
+
const [focus, setFocus] = react.useState(false);
|
|
70
|
+
const [singleSelectIndex, setSingleSelectIndex] = react.useState(defaultSelectedIndex !== null && defaultSelectedIndex !== void 0 ? defaultSelectedIndex : -1);
|
|
71
|
+
react.useEffect(() => {
|
|
72
|
+
if (!focus)
|
|
73
|
+
return;
|
|
74
|
+
const handleOutside = (event) => {
|
|
75
|
+
if (rootRef.current && !rootRef.current.contains(event.target)) {
|
|
76
|
+
setFocus(false);
|
|
77
|
+
}
|
|
107
78
|
};
|
|
108
|
-
|
|
79
|
+
document.addEventListener('mousedown', handleOutside);
|
|
80
|
+
return () => document.removeEventListener('mousedown', handleOutside);
|
|
81
|
+
}, [focus]);
|
|
82
|
+
const dynamicStyles = ctDesignStyleManager.useStyles((theme) => ({
|
|
83
|
+
placeHolderContainer: {
|
|
84
|
+
width: '100%',
|
|
85
|
+
height,
|
|
86
|
+
backgroundColor: '#fff',
|
|
87
|
+
borderRadius: 5,
|
|
88
|
+
flexDirection: 'row',
|
|
89
|
+
alignItems: 'center',
|
|
90
|
+
borderColor: focus ? theme.color.border.primary : '#e0e0e0',
|
|
91
|
+
borderWidth: 1,
|
|
92
|
+
},
|
|
93
|
+
placeHolderTextContainer: getPlaceHolderTextContainerStyles(height),
|
|
94
|
+
}), [focus, height]);
|
|
95
|
+
const singleSelectClickHandler = (item, index) => {
|
|
96
|
+
setSingleSelectIndex(index);
|
|
97
|
+
onItemSelect === null || onItemSelect === void 0 ? void 0 : onItemSelect(item, index);
|
|
98
|
+
setFocus(false);
|
|
109
99
|
};
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
100
|
+
const toggleDropDown = () => setFocus((state) => !state);
|
|
101
|
+
const isShownOnTop = showDropDownListOnTop;
|
|
102
|
+
const mergedRootClassName = ctDesignStyleManager.useWebMergeStyles([staticStyles.root], []);
|
|
103
|
+
const mergedPlaceHolderClassName = ctDesignStyleManager.useWebMergeStyles([dynamicStyles.placeHolderContainer, ...customPlaceHolderContainer], [dynamicStyles.placeHolderContainer, customPlaceHolderContainer]);
|
|
104
|
+
const mergedPlaceHolderTextClassName = ctDesignStyleManager.useWebMergeStyles([dynamicStyles.placeHolderTextContainer], [dynamicStyles.placeHolderTextContainer]);
|
|
105
|
+
const mergedChevronClassName = ctDesignStyleManager.useWebMergeStyles([staticStyles.chevronDownContainer], []);
|
|
106
|
+
const listPositionStyle = isShownOnTop ? { bottom: height } : { top: height };
|
|
107
|
+
const mergedListClassName = ctDesignStyleManager.useWebMergeStyles([
|
|
108
|
+
staticStyles.dropDownItemListContainer,
|
|
109
|
+
listPositionStyle,
|
|
110
|
+
staticStyles.scrollArea,
|
|
111
|
+
...customDropDownItemListContainer,
|
|
112
|
+
], [isShownOnTop, height, customDropDownItemListContainer]);
|
|
113
|
+
return (jsxRuntime.jsxs("div", { ref: rootRef, className: mergedRootClassName, children: [jsxRuntime.jsxs("div", { className: mergedPlaceHolderClassName, onClick: toggleDropDown, children: [jsxRuntime.jsx("div", { className: mergedPlaceHolderTextClassName, children: jsxRuntime.jsx(ctDesignTypography.Typography, { color: dropDownValue.length > 0 ? ctDesignTypography.TypographyColor.PRIMARY : ctDesignTypography.TypographyColor.DISABLED, lineClamp: 1, styleConfig: { root: customPlaceHolderTextContainer }, variant: ctDesignTypography.TypographyVariant.HM4, children: dropDownValue.length > 0 ? dropDownValue : placeHolder }) }), jsxRuntime.jsx("div", { className: mergedChevronClassName, children: jsxRuntime.jsx(ctDesignIcons.ChevronDown, {}) })] }), focus && (jsxRuntime.jsx("div", { className: mergedListClassName, children: itemList.map((item, index) => {
|
|
114
|
+
const dropdownItem = (renderItem === null || renderItem === void 0 ? void 0 : renderItem(item, index)) || (item === null || item === void 0 ? void 0 : item.label);
|
|
115
|
+
const isSelected = index === singleSelectIndex;
|
|
116
|
+
return (jsxRuntime.jsx(DropdownListItem, { item: item, index: index, isSelected: isSelected, dropdownItem: dropdownItem, onSelect: singleSelectClickHandler, customItemContainer: customDropDownItemContainer, customItemTextContainer: dropDownItemTextContainer }, `${item.value}-${index}`));
|
|
117
|
+
}) }))] }));
|
|
121
118
|
};
|
|
122
119
|
|
|
123
120
|
exports.Dropdown = Dropdown;
|