Skip to content

Commit

Permalink
TEC-4373: Improvements and changes needed in DS for step 2 (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelvermeuln authored Mar 19, 2024
1 parent cbfa371 commit e44c36a
Show file tree
Hide file tree
Showing 15 changed files with 173 additions and 84 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chardonnay",
"version": "1.0.21",
"version": "1.0.22",
"description": "A mobile first frontend framework made with wine",
"homepage": "https://vissimo-group.github.io/chardonnay/",
"main": "./dist/index.js",
Expand Down
38 changes: 30 additions & 8 deletions src/components/CardAddress/Select/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import React, { HTMLAttributes } from 'react'
import styled from 'styled-components'
import { Edit } from 'semillon'
import { Colors } from '../../../tokens'
import { CommomProps, ThemeType } from '../../../types'

interface CardAddressProps extends HTMLAttributes<HTMLInputElement> {
export interface CardAddressProps extends HTMLAttributes<HTMLInputElement> {
checked?: boolean
theme?: ThemeType
typeAddress?: string
address?: string
postcode?: string
complement?: string
onEdit?: () => void
isEditable?: boolean
}

const RadioButtonLabel = styled.label`
display: flex;
align-items: center;
justify-content: space-between;
`

interface Crosschecked extends CommomProps {
Expand Down Expand Up @@ -98,13 +102,24 @@ const ComplementLine = styled.span<CommomProps>`
text-align: left;
`

const Icon = styled.div`
cursor: pointer;
`

const ContainerRadioButton = styled.div`
display: flex;
align-items: flex-end;
`

const SelectAddress: React.FC<CardAddressProps> = ({
checked,
theme,
typeAddress,
address,
postcode,
complement,
onEdit,
isEditable,
...cardAddressProps
}) => {
return (
Expand All @@ -113,13 +128,20 @@ const SelectAddress: React.FC<CardAddressProps> = ({
theme={theme as ThemeType}
>
<RadioButtonLabel>
<RadioButtonInput
theme={theme as ThemeType}
type="radio"
checked={checked as boolean}
{...cardAddressProps}
/>
<RadioButtonText>{typeAddress}</RadioButtonText>
<ContainerRadioButton>
<RadioButtonInput
theme={theme as ThemeType}
type="radio"
checked={checked as boolean}
{...cardAddressProps}
/>
<RadioButtonText>{typeAddress}</RadioButtonText>
</ContainerRadioButton>
{isEditable && (
<Icon>
<Edit size={26} onClick={onEdit} />
</Icon>
)}
</RadioButtonLabel>
<AddressDetails>
<AddressLine>{address}</AddressLine>
Expand Down
2 changes: 2 additions & 0 deletions src/components/CardAddress/Shipping/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const ContainerShipping = styled.div<ShippingAddressProps>`
border-radius: 8px;
color: ${(props: CommomProps) => Colors[props.theme].neutral.neutral500};
background-color: ${(props: CommomProps) =>
Colors[props.theme].neutral.neutral100};
`

const Title = styled.span`
Expand Down
33 changes: 17 additions & 16 deletions src/components/Input/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, {
forwardRef,
useRef,
useEffect,
useImperativeHandle,
useState,
useCallback,
useEffect,
} from 'react'

import { maskInput, unMask } from './mask'
Expand All @@ -27,30 +28,30 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
...restProps
} = props

const [inputValue, setInputValue] = useState<string | undefined>(props.value)
const [inputValue, setInputValue] = useState<string | undefined>()
const inputRef = useRef<HTMLInputElement | null>(null)

useEffect(() => {
if (props.value) {
setInputValue(props.value)
}
}, [])

if (mask && inputValue) {
const originalValue = unMask(inputValue)
const makedValue = maskInput(originalValue, mask)
setInputValue(makedValue)
}
}, [inputValue])
useImperativeHandle(ref, () => inputRef.current!, [inputRef.current])

useImperativeHandle(ref, () => inputRef.current!, [])
const handleChange = useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
const newValue = event.target.value
const valueUnMask = unMask(newValue)
const valueMask = mask ? maskInput(valueUnMask, mask) : newValue

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const newValue = event.target.value
setInputValue(newValue)
if (props.onChange) {
props.onChange(event)
}
}
setInputValue(valueMask)
if (props.onChange) {
props.onChange(event)
}
},
[mask, props.onChange],
)

return (
<InputContainer theme={theme} {...props}>
Expand Down
40 changes: 20 additions & 20 deletions src/components/Input/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const regexMap: RegExpMapProps = {
}

export const masker = (
value: string,
pattern: string,
options?: PatternOptions,
value: string,
pattern: string,
options?: PatternOptions,
) => {
const patternCharList = pattern.split('')
const unmaskedValue = unMask(String(value))
Expand Down Expand Up @@ -55,8 +55,8 @@ export const masker = (
}

if (
output.length < patternCharList.length &&
/\W/.test(output[output.length - 1])
output.length < patternCharList.length &&
/\W/.test(output[output.length - 1])
) {
output.pop()
}
Expand All @@ -68,24 +68,24 @@ export const masker = (
}

const multimasker = (
value: string,
patterns: string[],
options?: PatternOptions,
value: string,
patterns: string[],
options?: PatternOptions,
) =>
masker(
value,
patterns.reduce(
(memo, pattern) => (value.length <= unMask(memo).length ? memo : pattern),
patterns[0],
),
options,
)
masker(
value,
patterns.reduce(
(memo, pattern) => (value.length <= unMask(memo).length ? memo : pattern),
patterns[0],
),
options,
)

export const maskInput = (
value: string,
pattern: string | [] | undefined,
pattern: string | [] | string[] ,
options?: PatternOptions,
): string =>
typeof pattern === 'string'
? masker(value, pattern || '', options)
: multimasker(value, pattern, options)
typeof pattern === 'string'
? masker(value, pattern || '', options)
: multimasker(value, pattern, options)
8 changes: 4 additions & 4 deletions src/components/Input/style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const InputContainer = styled.div<InputProps>`
position: relative;
min-width: 1rem;
height: 3.438rem;
margin-bottom: 20px;
display: flex;
align-items: center;
border-radius: ${BorderRadius['3']};
Expand Down Expand Up @@ -54,7 +53,7 @@ const InputContainer = styled.div<InputProps>`
}
`}
${({ disabled, theme }) =>
${({ disabled, theme }: InputProps & CommomProps) =>
disabled &&
css`
border-color: ${Colors[theme].neutral.neutral200} !important;
Expand All @@ -64,7 +63,7 @@ const InputContainer = styled.div<InputProps>`
}
`}
&:focus-within {
&:focus-within {
border-color: ${({ theme }: CommomProps) =>
Colors[theme].feedback.feedbackInfo100};
}
Expand All @@ -80,6 +79,7 @@ const InputCustom = styled.input<InputProps>`
background: none;
outline: none;
background-color: transparent;
width: 100%;
&:focus ~ ${Label}, &:not(:focus):not(:placeholder-shown) ~ ${Label} {
top: -0.02rem;
Expand Down Expand Up @@ -107,7 +107,7 @@ const InputCustom = styled.input<InputProps>`
`}
&:-webkit-autofill,
&:-webkit-autofill:focus {
&:-webkit-autofill:focus {
transition: background-color 600000s 0s;
background-color: transparent !important;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Input/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface InputProps extends HTMLAttributes<HTMLInputElement> {
error?: null | undefined | boolean
mask?: string | [] | undefined
value?: string | undefined
disabled?: boolean
theme?: ThemeType
iconLeft?: React.ReactNode
iconRight?: React.ReactNode
Expand Down
50 changes: 44 additions & 6 deletions src/components/Select/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const TemplateSelect = (props: SelectProps) => {
return (
<Select
label="Escolha uma opção"
iconRight={<ChevronDown size={26} color="black" />}
theme="light"
onChange={handleSelectChange}
value={selectedValue}
Expand All @@ -61,7 +60,10 @@ export const Enabled: Story = {
args: { disabled: false, error: false },

render: (args) => (
<TemplateSelect {...args}>
<TemplateSelect
{...args}
iconRight={<ChevronDown size={26} color="black" />}
>
<option value="home">Home address</option>
<option value="business">Business address</option>
</TemplateSelect>
Expand All @@ -73,7 +75,10 @@ export const Disabled: Story = {
args: { disabled: true, error: false },

render: (args) => (
<TemplateSelect {...args}>
<TemplateSelect
{...args}
iconRight={<ChevronDown size={26} color="black" />}
>
<option value="home">Home address</option>
<option value="business">Business address</option>
</TemplateSelect>
Expand All @@ -85,16 +90,16 @@ export const Error: Story = {
args: { disabled: false, error: true },

render: (args) => (
<TemplateSelect {...args}>
<TemplateSelect {...args} iconLeft={<Close size={26} color="red" />}>
<option value="home">Some error</option>
<option value="home">Home address</option>
<option value="business">Business address</option>
</TemplateSelect>
),
}

export const icons: Story = {
name: 'icons',
export const iconsLeft: Story = {
name: 'icon Left',
args: {},

render: (args) => (
Expand All @@ -105,3 +110,36 @@ export const icons: Story = {
</TemplateSelect>
),
}

export const iconsRight: Story = {
name: 'icon Right',
args: {},

render: (args) => (
<TemplateSelect
iconRight={<ChevronDown size={26} color="black" />}
{...args}
>
<option value="home">Some error</option>
<option value="home">Home address</option>
<option value="business">Business address</option>
</TemplateSelect>
),
}

export const icons: Story = {
name: 'icon Left and Right',
args: {},

render: (args) => (
<TemplateSelect
iconRight={<Close size={26} color="black" />}
iconLeft={<ChevronDown size={26} color="black" />}
{...args}
>
<option value="home">Some error</option>
<option value="home">Home address</option>
<option value="business">Business address</option>
</TemplateSelect>
),
}
Loading

0 comments on commit e44c36a

Please sign in to comment.