Skip to content

Commit

Permalink
Merge branch 'main' into modal
Browse files Browse the repository at this point in the history
  • Loading branch information
jongomez authored Oct 4, 2023
2 parents 774c51f + 85d05cd commit 2f5cc5d
Show file tree
Hide file tree
Showing 9 changed files with 375 additions and 16 deletions.
2 changes: 2 additions & 0 deletions packages/lsd-react/src/components/CSSBaseline/CSSBaseline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { ModalStyles } from '../Modal/Modal.styles'
import { ModalFooterStyles } from '../ModalFooter/ModalFooter.styles'
import { ModalBody } from '../ModalBody'
import { ModalBodyStyles } from '../ModalBody/ModalBody.styles'
import { NumberInputStyles } from '../NumberInput/NumberInput.styles'

const componentStyles: Array<ReturnType<typeof withTheme> | SerializedStyles> =
[
Expand Down Expand Up @@ -73,6 +74,7 @@ const componentStyles: Array<ReturnType<typeof withTheme> | SerializedStyles> =
ModalStyles,
ModalFooterStyles,
ModalBodyStyles,
NumberInputStyles,
]

export const CSSBaseline: React.FC<{ theme?: Theme }> = ({
Expand Down
36 changes: 26 additions & 10 deletions packages/lsd-react/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export type DropdownProps = CommonProps &
value?: string | string[]
onChange?: (value: string | string[]) => void
variant?: 'outlined' | 'outlined-bottom'
isOpen?: boolean
onToggle?: (open: boolean) => void
}

export const Dropdown: React.FC<DropdownProps> & {
Expand All @@ -43,33 +45,47 @@ export const Dropdown: React.FC<DropdownProps> & {
disabled = false,
supportingText,
triggerLabel,

value = [],
onChange,
options = [],
multi = false,
variant = 'outlined',
isOpen,
onToggle,
...props
}) => {
const commonProps = useCommonProps(props)
const containerRef = useRef<HTMLDivElement>(null)
const [open, setOpen] = useState(false)
const isControlled = isOpen !== undefined
const [openState, setOpenState] = useState(false)

if (isControlled && isOpen !== openState) setOpenState(isOpen)

const { select, isSelected, selected } = useSelect(options, value, {
multi,
onChange,
onDone: () => {
setOpen(false)
setOpenState(false)
},
})

const handleToggle = (open: boolean) => {
if (isControlled) {
onToggle && onToggle(open)
} else {
setOpenState(open)
}
}

const onTrigger = () => {
!disabled && setOpen((value) => !value)
if (disabled) return

handleToggle(!openState)
}

useEffect(() => {
if (disabled && open) setOpen(false)
}, [open, disabled])
if (disabled && openState && !isControlled) setOpenState(false)
}, [openState, disabled, isControlled])

const buttonId = props?.id ?? (props.id || 'dropdown') + '-input'

Expand All @@ -84,7 +100,7 @@ export const Dropdown: React.FC<DropdownProps> & {
dropdownClasses[size],
error && dropdownClasses.error,
disabled && dropdownClasses.disabled,
open && dropdownClasses.open,
openState && dropdownClasses.open,
variant === 'outlined'
? dropdownClasses.outlined
: dropdownClasses.outlinedBottom,
Expand Down Expand Up @@ -121,7 +137,7 @@ export const Dropdown: React.FC<DropdownProps> & {
<ErrorIcon color="primary" className={dropdownClasses.icon} />
)}

{open ? (
{openState ? (
<ArrowUpIcon
color="primary"
className={dropdownClasses.menuIcon}
Expand All @@ -148,8 +164,8 @@ export const Dropdown: React.FC<DropdownProps> & {
<Portal id="dropdown">
<DropdownMenu
handleRef={containerRef}
open={open}
onClose={() => setOpen(false)}
open={openState}
onClose={() => handleToggle(false)}
size={size}
genericFontFamily={props.genericFontFamily}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const numberInputClasses = {
root: `lsd-number-input`,
label: 'lsd-number-input__label',

mainContainer: `lsd-number-input__main-container`,

inputContainer: `lsd-number-input__input-container`,
input: `lsd-number-input__input`,

errorIcon: `lsd-number-input__error-icon`,
plusMinusIcons: `lsd-number-input__plus-minus-icons`,

supportingText: 'lsd-number-input__supporting-text',

disabled: `lsd-number-input--disabled`,
error: 'lsd-number-input--error',

large: `lsd-number-input--large`,
medium: `lsd-number-input--medium`,
small: `lsd-number-input--small`,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Meta, Story } from '@storybook/react'
import { NumberInput, NumberInputProps } from './NumberInput'

export default {
title: 'NumberInput',
component: NumberInput,
argTypes: {
size: {
type: {
name: 'enum',
value: ['small', 'medium', 'large'],
},
defaultValue: 'large',
},
},
} as Meta

export const Root: Story<NumberInputProps> = ({ ...args }) => {
return <NumberInput {...args} />
}

Root.args = {
id: 'label',
size: 'large',
supportingText: 'Supporting text',
disabled: false,
value: undefined,
onChange: undefined,
error: false,
errorIcon: false,
min: -10,
max: 10,
step: 1,
label: 'Label',
}
137 changes: 137 additions & 0 deletions packages/lsd-react/src/components/NumberInput/NumberInput.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { css } from '@emotion/react'
import { numberInputClasses } from './NumberInput.classes'

export const NumberInputStyles = css`
.${numberInputClasses.root} {
width: auto;
box-sizing: border-box;
}
.${numberInputClasses.mainContainer}:hover {
text-decoration: underline;
}
.${numberInputClasses.error} {
.${numberInputClasses.mainContainer} {
text-decoration: line-through;
}
}
.${numberInputClasses.label} {
display: block;
}
.${numberInputClasses.plusMinusIcons} {
display: flex;
flex-shrink: 0;
}
.${numberInputClasses.inputContainer} {
box-sizing: border-box;
border: 1px solid rgb(var(--lsd-border-primary));
border-left: 0px;
border-right: 0px;
}
.${numberInputClasses.errorIcon} {
cursor: pointer;
display: flex;
align-items: center;
padding: 10px 8px;
}
.${numberInputClasses.inputContainer} {
display: flex;
align-items: center;
justify-content: space-between;
}
.${numberInputClasses.disabled} {
opacity: 0.34;
}
.${numberInputClasses.mainContainer} {
display: flex;
align-items: center;
}
.${numberInputClasses.input} {
border: none;
outline: none;
font-size: 14px;
color: rgb(var(--lsd-text-primary));
background: none;
text-align: center;
padding: 0 4px;
}
.${numberInputClasses.input}::-webkit-inner-spin-button {
display: none;
-webkit-appearance: none;
}
.${numberInputClasses.input}:hover {
outline: none;
}
.${numberInputClasses.supportingText} {
position: absolute;
}
.${numberInputClasses.large} {
.${numberInputClasses.label} {
margin: 0 0 6px 18px;
}
.${numberInputClasses.inputContainer} {
height: 40px;
}
.${numberInputClasses.input} {
width: 62px;
}
.${numberInputClasses.plusMinusIcons} {
height: 40px;
width: 40px;
}
.${numberInputClasses.supportingText} {
margin: 6px 18px 0 18px;
}
}
.${numberInputClasses.medium} {
.${numberInputClasses.label} {
margin: 0 0 6px 14px;
}
.${numberInputClasses.inputContainer} {
height: 32px;
}
.${numberInputClasses.input} {
width: 58px;
}
.${numberInputClasses.plusMinusIcons} {
height: 32px;
width: 32px;
}
.${numberInputClasses.supportingText} {
margin: 6px 14px 0 14px;
}
}
.${numberInputClasses.small} {
.${numberInputClasses.label} {
margin: 0 0 6px 12px;
}
.${numberInputClasses.inputContainer} {
height: 28px;
}
.${numberInputClasses.input} {
width: 50px;
}
.${numberInputClasses.plusMinusIcons} {
height: 28px;
width: 28px;
}
.${numberInputClasses.supportingText} {
margin: 6px 12px 0 12px;
}
}
`
Loading

0 comments on commit 2f5cc5d

Please sign in to comment.