-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update changes * add props type * update version and remove on dash * theme in progress * semantics in progress * button semantics in progress * button and switch semantics added * added more semantics * added all the semantics * added new theme support * added theme type * updated comment * fixed types and file structure * fixed input semantics name * removed curropt dropdown utils file * implemented textarea component * added new color typesin Box * fixed texarea description color --------- Co-authored-by: corlard3y <[email protected]>
- Loading branch information
1 parent
0c92a23
commit 78dbb0f
Showing
9 changed files
with
206 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
import { Asterisk } from 'blocks/icons'; | ||
import { Text } from 'blocks/text/Text'; | ||
import React, { forwardRef } from 'react'; | ||
import styled, { FlattenSimpleInterpolation, css } from 'styled-components'; | ||
|
||
export type TextAreaProps = { | ||
css?: FlattenSimpleInterpolation; | ||
description?: string; | ||
disabled?: boolean; | ||
error?: boolean; | ||
errorMessage?: string; | ||
label?: string; | ||
numberOfLines?: number; | ||
onChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void; | ||
placeholder?: string; | ||
required?: boolean; | ||
resizable?: boolean; | ||
success?: boolean; | ||
totalCount?: number; | ||
value: string; | ||
}; | ||
|
||
const Container = styled.div<{ css?: FlattenSimpleInterpolation }>` | ||
align-items: flex-start; | ||
display: flex; | ||
flex-direction: column; | ||
flex: 1 0 0; | ||
gap: var(--spacing-xxs, 8px); | ||
/* Custom CSS applied via styled component css prop */ | ||
${(props) => props.css || ''}; | ||
`; | ||
|
||
const StyledTextArea = styled.textarea<{ | ||
error?: boolean; | ||
success?: boolean; | ||
resizable?: boolean; | ||
}>` | ||
${({ theme, resizable, success, error }) => { | ||
const colors = theme?.blocksTheme?.colors; | ||
const defaultState = error ? 'danger' : success ? 'success' : 'default'; | ||
const focusState = error ? 'danger' : success ? 'success' : 'focus'; | ||
return css` | ||
align-self: stretch; | ||
align-items: flex-start; | ||
border-radius: var(--radius-xs, 12px); | ||
border: 1.5px solid | ||
var(--components-inputs-stroke-${defaultState}, ${colors[`components-inputs-stroke-${defaultState}`]}); | ||
background: var( | ||
--components-inputs-background-${defaultState}, | ||
${colors[`components-inputs-background-${defaultState}`]} | ||
); | ||
color: var(--components-inputs-text-default, ${colors['components-inputs-text-default']}); | ||
display: flex; | ||
font-family: var(--font-family); | ||
font-size: 14px; | ||
font-style: normal; | ||
font-weight: 400; | ||
gap: var(--spacing-none, 0px); | ||
line-height: 20px; | ||
padding: var(--spacing-xs, 12px); | ||
::placeholder { | ||
color: var(--components-inputs-text-placeholder, ${colors['components-inputs-text-placeholder']}); | ||
} | ||
resize: ${resizable ? 'vertical' : 'none'}; | ||
&:hover { | ||
outline: none; | ||
} | ||
&:focus { | ||
border: 1.5px solid | ||
var(--components-inputs-stroke-${focusState}, ${colors[`components-inputs-stroke-${focusState}`]}); | ||
outline: none; | ||
} | ||
&:disabled { | ||
border: 1.5px solid var(--components-inputs-stroke-default, ${colors['components-inputs-stroke-default']}); | ||
background: var(--components-inputs-background-disabled, ${colors['components-inputs-background-disabled']}); | ||
cursor: not-allowed; | ||
color: var(--components-inputs-text-disabled, ${colors['components-inputs-text-disabled']}); | ||
} | ||
`; | ||
}} | ||
`; | ||
|
||
const LabelContainer = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
width: 100%; | ||
`; | ||
|
||
const LabelTextContainer = styled.div` | ||
display: flex; | ||
align-items: flex-start; | ||
gap: var(--spacing-xxxs, 4px); | ||
`; | ||
|
||
export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>( | ||
( | ||
{ | ||
css, | ||
description, | ||
disabled, | ||
error, | ||
errorMessage, | ||
label, | ||
numberOfLines = 4, | ||
onChange, | ||
placeholder, | ||
required, | ||
resizable, | ||
success, | ||
totalCount, | ||
value, | ||
}, | ||
ref | ||
) => { | ||
return ( | ||
<Container css={css}> | ||
{label && ( | ||
<LabelContainer> | ||
<Text | ||
variant="h6-semibold" | ||
color="components-inputs-text-default" | ||
> | ||
<LabelTextContainer> | ||
{label} | ||
{required && <Asterisk size={4.6} />} | ||
</LabelTextContainer> | ||
</Text> | ||
{totalCount && ( | ||
<Text | ||
variant="c-regular" | ||
color="components-inputs-text-secondary" | ||
>{`${value?.length || 0} / ${totalCount}`}</Text> | ||
)} | ||
</LabelContainer> | ||
)} | ||
<StyledTextArea | ||
disabled={disabled} | ||
error={error} | ||
onChange={onChange} | ||
placeholder={placeholder} | ||
ref={ref} | ||
required={required} | ||
resizable={resizable} | ||
rows={numberOfLines} | ||
success={success} | ||
value={value} | ||
/> | ||
{description && ( | ||
<Text | ||
variant="c-regular" | ||
color={ | ||
success || error | ||
? 'components-inputs-text-default' | ||
: disabled | ||
? 'components-inputs-text-disabled' | ||
: 'components-inputs-text-placeholder' | ||
} | ||
> | ||
{description} | ||
</Text> | ||
)} | ||
{errorMessage && ( | ||
<Text | ||
variant="c-regular" | ||
color="components-inputs-text-danger" | ||
> | ||
{errorMessage} | ||
</Text> | ||
)} | ||
</Container> | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './TextArea'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters