Skip to content

Commit

Permalink
feat: update option
Browse files Browse the repository at this point in the history
  • Loading branch information
Dendi committed Jan 15, 2025
1 parent 52a91c7 commit de96b9d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "n6-ui",
"version": "1.2.6",
"version": "1.2.7",
"description": "N6 Network UI Framework",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -80,4 +80,4 @@
"tailwindcss": "^3.4.16",
"zustand": "^5.0.2"
}
}
}
16 changes: 12 additions & 4 deletions src/NDropdown/NDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ interface NDropdownOption {

interface NDropdownProps {
options: NDropdownOption[];
placeholder?: string;
defaultValue?: NDropdownOption;
onSelect: (selected: NDropdownOption) => void;
className?: string; // 支持传入自定义样式
}

const NDropdown: React.FC<NDropdownProps> = ({ options, placeholder = 'Select an option', onSelect, className }) => {
const NDropdown: React.FC<NDropdownProps> = ({
options,
defaultValue = {
value: 'select',
label: 'Select an option',
},
onSelect,
className,
}) => {
const [isOpen, setIsOpen] = useState(false);
const [selectedOption, setSelectedOption] = useState<NDropdownOption | null>(null);
const [selectedOption, setSelectedOption] = useState<NDropdownOption>(defaultValue);
const dropdownRef = useRef<HTMLDivElement>(null);

const handleOptionClick = (option: NDropdownOption) => {
Expand Down Expand Up @@ -42,7 +50,7 @@ const NDropdown: React.FC<NDropdownProps> = ({ options, placeholder = 'Select an
onClick={() => setIsOpen(!isOpen)}
className="bg-white flex w-full justify-center px-4 py-2 text-left shadow-sm"
>
<span>{selectedOption?.label || placeholder}</span>
<span>{selectedOption?.label}</span>
<span className={`ml-2 transform transition-transform duration-300 ${isOpen ? 'rotate-180' : 'rotate-0'}`}>
<NDropdownIcon />
</span>
Expand Down

0 comments on commit de96b9d

Please sign in to comment.