From 09618cd01a335ab03659656f6a8d6d84ed9bcb27 Mon Sep 17 00:00:00 2001 From: Max Holman Date: Sun, 11 Dec 2022 19:01:49 +0800 Subject: [PATCH] feat: text overflow and text aligns --- lib/core.css.ts | 37 ++++++++++++++++++++++++++++++++++++- lib/core.tsx | 13 ++++++++++++- src/App.tsx | 8 ++++++-- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/lib/core.css.ts b/lib/core.css.ts index 79ad411..3e517df 100644 --- a/lib/core.css.ts +++ b/lib/core.css.ts @@ -1,6 +1,20 @@ -import { styleVariants } from '@vanilla-extract/css'; +import { style, StyleRule, styleVariants } from '@vanilla-extract/css'; import { genericVars } from './design-system.css.js'; +export type TextAlign = 'start' | 'end' | 'center'; + +export const textAlignVariants = styleVariants({ + start: { + textAlign: 'start', + }, + end: { + textAlign: 'end', + }, + center: { + textAlign: 'center', + }, +}); + export const marginVariants = styleVariants(genericVars.space, (space) => [ { margin: space, @@ -45,3 +59,24 @@ export const paddingInlineVariants = styleVariants( }, ], ); + +export type TextOverflow = 'ellipsis' | 'clip'; + +const textOverflowCssProps: Record = { + ellipsis: { + textOverflow: 'ellipsis', + }, + clip: { + textOverflow: 'clip', + }, +}; + +const textOverflowBase = style({ + overflow: 'hidden', + whiteSpace: 'nowrap', +}); + +export const textOverflowVariants = styleVariants( + textOverflowCssProps, + (value) => [textOverflowBase, value], +); diff --git a/lib/core.tsx b/lib/core.tsx index 3aca811..be65eeb 100644 --- a/lib/core.tsx +++ b/lib/core.tsx @@ -8,6 +8,10 @@ import { paddingBlockVariants, paddingInlineVariants, paddingVariants, + TextAlign, + textAlignVariants, + TextOverflow, + textOverflowVariants, } from './core.css.js'; import { Align, alignItems } from './layout.css.js'; import { Tooltip } from './tooltip.js'; @@ -32,6 +36,9 @@ export type BoxBasedComponentProps = paddingBlock?: Space | undefined; paddingInline?: Space | undefined; tooltip?: ReactNode; + textAlign?: TextAlign | undefined; + textOverflow?: TextOverflow | undefined; + // rounded } >; @@ -48,9 +55,11 @@ const BoxInner = ( padding, paddingBlock, paddingInline, + textAlign, + textOverflow, tooltip, ...props - }: BoxBasedComponentProps, + }: PropsWithChildren>, ref: React.ForwardedRef, ) => { const el = createElement( @@ -66,6 +75,8 @@ const BoxInner = ( padding && paddingVariants[padding], paddingBlock && paddingBlockVariants[paddingBlock], paddingInline && paddingInlineVariants[paddingInline], + textAlign && textAlignVariants[textAlign], + textOverflow && textOverflowVariants[textOverflow], className, ) || undefined, ref, diff --git a/src/App.tsx b/src/App.tsx index 984077d..920b3d0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -40,7 +40,9 @@ export const App: FC = () => { - Color Scheme + + Color Scheme + { - Contrast Scheme + + Contrast Scheme +