teachable-design-system 0.3.8 → 0.3.9
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/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/types/components/Dropdown/Dropdown 2.d.ts +3 -0
- package/dist/types/components/Dropdown/Dropdown 2.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/components/Dropdown/Dropdown 2.tsx +57 -0
- package/src/components/Input/style.ts +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dropdown 2.d.ts","sourceRoot":"","sources":["../../../../src/components/Dropdown/Dropdown 2.tsx"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAC;AAIzD,wBAAgB,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAC,EAAE,aAAa,2CAmD3F"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {DropdownProps} from "../../types/Dropdown.types";
|
|
3
|
+
import {StyledBox, StyledDropDown, StyledText, StyledLabel, StyledIcon, StyledOptions, StyledOption} from "./style";
|
|
4
|
+
import { arrowDownIconBase64 } from '../../assets/icons';
|
|
5
|
+
|
|
6
|
+
export function Dropdown({size, options, onSelect, label, placeholder, width}: DropdownProps) {
|
|
7
|
+
const [open, setOpen] = React.useState(false);
|
|
8
|
+
const [selected, setSelected] = React.useState<string | null>(null);
|
|
9
|
+
const ref = React.useRef<HTMLDivElement>(null);
|
|
10
|
+
|
|
11
|
+
React.useEffect(() => {
|
|
12
|
+
const handleClickOutside = (e: MouseEvent) => {
|
|
13
|
+
if (ref.current && !ref.current.contains(e.target as Node)) {
|
|
14
|
+
setOpen(false);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
18
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
19
|
+
}, []);
|
|
20
|
+
|
|
21
|
+
const handleSelect = (option: string) => {
|
|
22
|
+
setSelected(option);
|
|
23
|
+
onSelect?.(option);
|
|
24
|
+
setOpen(false);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div style={{position: 'relative'}}>
|
|
30
|
+
<StyledLabel>{label}</StyledLabel>
|
|
31
|
+
<StyledDropDown onClick={() => setOpen((prev) => !prev)}
|
|
32
|
+
size={size}
|
|
33
|
+
width={width}
|
|
34
|
+
isOpen={open}
|
|
35
|
+
>
|
|
36
|
+
<StyledBox>
|
|
37
|
+
<StyledText
|
|
38
|
+
size={size}
|
|
39
|
+
isOpen={open}
|
|
40
|
+
>{selected ?? placeholder}</StyledText>
|
|
41
|
+
<StyledIcon size={size}>
|
|
42
|
+
<img src={arrowDownIconBase64} alt="dropdown icon" style={{width:'100%', height:'100%'}}/>
|
|
43
|
+
</StyledIcon>
|
|
44
|
+
</StyledBox>
|
|
45
|
+
</StyledDropDown>
|
|
46
|
+
{open && (
|
|
47
|
+
<StyledOptions ref={ref} size={size}>
|
|
48
|
+
{options?.map((option) => (
|
|
49
|
+
<StyledOption key={option} onClick={() => handleSelect(option)} size={size} isSelected={option === selected}>
|
|
50
|
+
{option}
|
|
51
|
+
</StyledOption>
|
|
52
|
+
))}
|
|
53
|
+
</StyledOptions>
|
|
54
|
+
)}
|
|
55
|
+
</div>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
@@ -81,7 +81,7 @@ export const StyledInput = styled.input<StyledInputProps>`
|
|
|
81
81
|
padding: ${(props) => (props.isPassword ? "0px 48px 0px 16px" : "0px 16px")};
|
|
82
82
|
font-family: ${typography.fontFamily.primary};
|
|
83
83
|
border: 1px solid ${colors.input.border};
|
|
84
|
-
border-radius:
|
|
84
|
+
border-radius: 8px;
|
|
85
85
|
outline: none;
|
|
86
86
|
transition: all 0.2s ease;
|
|
87
87
|
background-color: ${(props) =>
|