import React, { useState } from 'react'; import styled from 'styled-components'; import v from '../../styles/Variables'; // theme for default styles, addon like cart {jsx}, shadow? interface Props { /** * valid hex/rgba color for the background */ background?: string; /** * callback function when the button is clicked */ callback: (p: string, q: string) => void; /** * font color to be used, can be hex, rgba, or a variable */ color?: string; /** * the text of the button or selected item */ dropTitle: string; /** * dropdown width in pixels */ dropdownWidth?: number; /** * font size in pixels */ fontSize?: number; /** * if the button should be inline-block or block */ fullWidth?: boolean; /** * padding applied to all 4 sides, in pixels, as a string (valid css) */ padding?: string; /** * the rounding amount of the button */ radius?: 'rounded' | 'square' | 'pill'; /** * id of the element */ id?: string; /** * the list options of the button */ options?: Array; /** * If using our variables, any valid color variable, or default, dark, none */ theme?: string; /** * extra classes to be applied */ themeClass?: string; /** * show Chevron on the left side of the dropdown */ onLeftChevron?: boolean; /** * left position to be applied for the Chevron. use it along with onLeftChevron */ chevronPositionLeft?: string; /** * right position to be applied for the Chevron. use it for the default right chevron. */ chevronPositionRight?: string; /** * top position to be applied for the Chevron. */ chevronPositionTop?: string; } interface Options { title: string; value: string; bottomTitle: string; showBottomTitle: boolean; } interface DropdownBtnStyle { background: string; color: string; fontSize: number; fullWidth: boolean; padding: string; radius: 'rounded' | 'pill' | 'square'; theme: string; isHidden?: boolean; onLeftChevron?: boolean; } interface AngleDownLeftStyle { chevronPositionLeft?: string; chevronPositionTop?: string; } interface AngleDownRightStyle { chevronPositionRight?: string; chevronPositionTop?: string; } interface DropdownWrapStyle { fullWidth: boolean; } interface DropdownContentStyle { dropdownWidth: number; isHidden: boolean; children: React.ReactNode; fullWidth: boolean; } const Dropdown = ({ background = v.colors.light, callback, color = v.colors.dark, dropTitle, dropdownWidth = 160, fontSize = 14, fullWidth = false, id = 'dropdown', options = [ { title: 'Dropdown here', value: '0', bottomTitle: 'Bottom title here', showBottomTitle: true }, { title: 'Dropdown here', value: '1', bottomTitle: 'Bottom title here', showBottomTitle: false }, ], padding = '10px 40px', radius = 'rounded', theme = 'default', themeClass, onLeftChevron = false, chevronPositionLeft, chevronPositionRight, chevronPositionTop, }: Props) => { const [isHidden, setIsHidden] = useState(true); return ( { setTimeout(() => { setIsHidden(true); }, 200); }} onClick={() => { setTimeout(() => { setIsHidden(!isHidden); }, 200); }} className={`nwc--button`} background={background} color={color} fontSize={fontSize} fullWidth={fullWidth} padding={padding} radius={radius} isHidden={isHidden} theme={theme} id={id} aria-controls={`${id}--content`} > {dropTitle} {onLeftChevron && (