diff --git a/src/blocks/Blocks.types.ts b/src/blocks/Blocks.types.ts index 4c23696399..07145040d5 100644 --- a/src/blocks/Blocks.types.ts +++ b/src/blocks/Blocks.types.ts @@ -1,6 +1,7 @@ import { HTMLAttributes } from 'react'; import { BoxResponsiveCSSProperties, BoxResponsiveCSSPropertiesData, BoxResponsivePropValues } from './box'; import { blocksColorsLegacy } from './Blocks.colors'; +import { ThemeColors } from './theme/Theme.types'; import { SkeletonResponsiveCSSProperties, SkeletonResponsiveCSSPropertiesData, @@ -57,7 +58,8 @@ export type BlocksColors = keyof BlocksColorData; export type ThemeMode = 'light' | 'dark'; -export type ThemeModeColors = Record; +// TODO: Remove BlocksColors +export type ThemeModeColors = Record; export type BorderValue = `${number}px ${string} ${BlocksColors}` | 'none'; diff --git a/src/blocks/Blocks.utils.ts b/src/blocks/Blocks.utils.ts index e537e938e2..5797d0cfbe 100644 --- a/src/blocks/Blocks.utils.ts +++ b/src/blocks/Blocks.utils.ts @@ -14,6 +14,7 @@ import { BorderValue, RadiusType, } from './Blocks.types'; +import { ThemeColors } from './theme/Theme.types'; /** * @param propName @@ -135,10 +136,13 @@ export const getResponsiveCSS = (data: ResponsiveCSSPropertyData[]) => { }; /** + * @deprecated * @param color * @returns color as a css variable: var(--primary) + * + * // TODO: Remove this function. We don't need it. */ -export const getBlocksColor = (mode: ThemeMode, color?: BlocksColors | ThemeModeColors) => { +export const getBlocksColor = (mode: ThemeMode, color?: BlocksColors | ThemeModeColors | ThemeColors) => { // If color is not given return undefined, to avoid any breakages if (!color) return color; diff --git a/src/blocks/box/Box.tsx b/src/blocks/box/Box.tsx index 80d5ae4f7a..4a25537cc1 100644 --- a/src/blocks/box/Box.tsx +++ b/src/blocks/box/Box.tsx @@ -32,6 +32,7 @@ const StyledBox = styled.div.withConfig({ `; const Box = forwardRef(({ as = 'div', ...props }, ref) => { const { mode } = useBlocksTheme(); + // TODO: We need to remove color dependency from BlocksColors | ThemeModeColors to fix this error return ( (({ as = 'p', ...props }, ref) => { const { mode } = useBlocksTheme(); return ( + // TODO: We need to remove color dependency from BlocksColors | ThemeModeColors to fix this error ) => 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( + ( + { + css, + description, + disabled, + error, + errorMessage, + label, + numberOfLines = 4, + onChange, + placeholder, + required, + resizable, + success, + totalCount, + value, + }, + ref + ) => { + return ( + + {label && ( + + + + {label} + {required && } + + + {totalCount && ( + {`${value?.length || 0} / ${totalCount}`} + )} + + )} + + {description && ( + + {description} + + )} + {errorMessage && ( + + {errorMessage} + + )} + + ); + } +); diff --git a/src/blocks/textarea/index.ts b/src/blocks/textarea/index.ts new file mode 100644 index 0000000000..4853311ce1 --- /dev/null +++ b/src/blocks/textarea/index.ts @@ -0,0 +1 @@ +export * from './TextArea'; diff --git a/src/blocks/theme/Theme.types.ts b/src/blocks/theme/Theme.types.ts index 1577d79807..561efd63cb 100644 --- a/src/blocks/theme/Theme.types.ts +++ b/src/blocks/theme/Theme.types.ts @@ -11,12 +11,14 @@ type ColorSemantics = typeof colorSemantics; type StringKeys = Extract; -type ThemeColors = { +type ThemeColorsConfig = { [K1 in StringKeys as `${K1}-${StringKeys}`]: string; }; +export type ThemeColors = keyof ThemeColorsConfig; + export type Theme = { - colors: ThemeColors; + colors: ThemeColorsConfig; blur: typeof blurVariables; borderRadius: typeof borderRadiusVariables; borderSize: typeof borderSizeVariables;