diff --git a/src/common/Base.tsx b/src/common/Base.tsx index e13d3d8e..6d63d5b9 100644 --- a/src/common/Base.tsx +++ b/src/common/Base.tsx @@ -1,4 +1,5 @@ import { CSSProperties, DetailedHTMLProps, FC, HTMLAttributes, LegacyRef, useMemo } from 'react'; +import { ColorVariantType } from './types/ColorVariantType'; import { OverflowType } from './types/OverflowType'; import { PositionType } from './types/PositionType'; @@ -13,12 +14,13 @@ export interface BaseProps extends DetailedHTMLProps> = props => { - const { ref = null, innerRef = null, fit = false, grow = false, shrink = false, fullWidth = false, fullHeight = false, overflow = null, position = null, pointer = false, classNames = [], className = '', style = {}, ...rest } = props; + const { ref = null, innerRef = null, fit = false, grow = false, shrink = false, fullWidth = false, fullHeight = false, overflow = null, position = null, pointer = false, textColor = null, classNames = [], className = '', style = {}, ...rest } = props; const getClassNames = useMemo(() => { @@ -38,10 +40,12 @@ export const Base: FC> = props => if(pointer) newClassNames.push('cursor-pointer'); + if(textColor) newClassNames.push('text-' + textColor); + if(classNames.length) newClassNames.push(...classNames); return newClassNames; - }, [ fit, grow, shrink, fullWidth, fullHeight, overflow, position, pointer, classNames ]); + }, [ fit, grow, shrink, fullWidth, fullHeight, overflow, position, pointer, textColor, classNames ]); const getClassName = useMemo(() => { diff --git a/src/common/Column.tsx b/src/common/Column.tsx index 810a96ef..e66d29cb 100644 --- a/src/common/Column.tsx +++ b/src/common/Column.tsx @@ -1,4 +1,5 @@ import { FC, useMemo } from 'react'; +import { useGridContext } from './context/GridContext'; import { Flex, FlexProps } from './Flex'; import { ColumnSizesType } from './types/ColumnSizesType'; @@ -11,17 +12,25 @@ export interface ColumnProps extends FlexProps export const Column: FC = props => { const { size = 0, column = true, gap = 2, classNames = [], ...rest } = props; + const { isCssGrid = false } = useGridContext(); const getClassNames = useMemo(() => { const newClassNames: string[] = []; - if(size) newClassNames.push('g-col-' + size); + if(size) + { + let colClassName = `col-${ size }`; + + if(isCssGrid) colClassName = `g-${ colClassName }`; + + newClassNames.push(colClassName); + } if(classNames.length) newClassNames.push(...classNames); return newClassNames; - }, [ size, classNames ]); + }, [ size, isCssGrid, classNames ]); return ; } diff --git a/src/common/Grid.tsx b/src/common/Grid.tsx index fd41ec40..fce48416 100644 --- a/src/common/Grid.tsx +++ b/src/common/Grid.tsx @@ -1,5 +1,6 @@ import { CSSProperties, FC, useMemo } from 'react'; import { Base, BaseProps } from './Base'; +import { GridContextProvider } from './context/GridContext'; import { SpacingType } from './types/SpacingType'; export interface GridProps extends BaseProps @@ -10,11 +11,12 @@ export interface GridProps extends BaseProps grow?: boolean; inline?: boolean; gap?: SpacingType; + maxContent?: boolean; } export const Grid: FC = props => { - const { columnCount = 0, columnMinWidth = 40, columnMinHeight = 40, grow = false, inline = false, gap = 2, classNames = [], style = {}, ...rest } = props; + const { columnCount = 0, columnMinWidth = 40, columnMinHeight = 40, grow = false, inline = false, gap = 2, maxContent = false, classNames = [], style = {}, ...rest } = props; const getClassNames = useMemo(() => { @@ -48,10 +50,16 @@ export const Grid: FC = props => newStyle.gridTemplateColumns = 'repeat(auto-fill, minmax(var(--nitro-grid-column-min-width, 45px), 1fr)'; } + if(maxContent) newStyle.gridTemplateRows = 'max-content'; + if(Object.keys(style).length) newStyle = { ...newStyle, ...style }; return newStyle; - }, [ columnCount, columnMinWidth, columnMinHeight, grow, style ]); + }, [ columnCount, columnMinWidth, columnMinHeight, grow, maxContent, style ]); - return ; + return ( + + + + ); } diff --git a/src/common/Text.tsx b/src/common/Text.tsx index ac6b0c40..6be5c21f 100644 --- a/src/common/Text.tsx +++ b/src/common/Text.tsx @@ -9,15 +9,18 @@ export interface TextProps extends BaseProps variant?: ColorVariantType; fontWeight?: FontWeightType; fontSize?: FontSizeType; + bold?: boolean; underline?: boolean; + italics?: boolean; truncate?: boolean; center?: boolean; textEnd?: boolean; + small?: boolean; } export const Text: FC = props => { - const { variant = 'black', fontWeight = null, fontSize = 0, underline = false, truncate = false, center = false, textEnd = false, ...rest } = props; + const { variant = 'black', fontWeight = null, fontSize = 0, bold = false, underline = false, italics = false, truncate = false, center = false, textEnd = false, small = false, ...rest } = props; const getClassNames = useMemo(() => { @@ -25,20 +28,26 @@ export const Text: FC = props => if(variant) newClassNames.push('text-' + variant); + if(bold) newClassNames.push('fw-bold'); + if(fontWeight) newClassNames.push('fw-' + fontWeight); if(fontSize) newClassNames.push('fs-' + fontSize); if(underline) newClassNames.push('text-decoration-underline'); + if(italics) newClassNames.push('fst-italic'); + if(truncate) newClassNames.push('text-truncate'); if(center) newClassNames.push('text-center'); if(textEnd) newClassNames.push('text-end'); + if(small) newClassNames.push('small'); + return newClassNames; - }, [ variant, fontWeight, fontSize, underline, truncate, center, textEnd ]); + }, [ variant, fontWeight, fontSize, bold, underline, italics, truncate, center, textEnd, small ]); return ; } diff --git a/src/common/context/GridContext.tsx b/src/common/context/GridContext.tsx new file mode 100644 index 00000000..821e01b7 --- /dev/null +++ b/src/common/context/GridContext.tsx @@ -0,0 +1,17 @@ +import { createContext, FC, ProviderProps, useContext } from 'react'; + +export interface IGridContext +{ + isCssGrid: boolean; +} + +const GridContext = createContext({ + isCssGrid: false +}); + +export const GridContextProvider: FC> = props => +{ + return { props.children } +} + +export const useGridContext = () => useContext(GridContext); diff --git a/src/common/types/ColorVariantType.ts b/src/common/types/ColorVariantType.ts index 7c266542..a4e42e69 100644 --- a/src/common/types/ColorVariantType.ts +++ b/src/common/types/ColorVariantType.ts @@ -1 +1 @@ -export type ColorVariantType = 'primary' | 'success' | 'danger' | 'secondary' | 'link' | 'black' | 'white' | 'dark' | 'warning'; +export type ColorVariantType = 'primary' | 'success' | 'danger' | 'secondary' | 'link' | 'black' | 'white' | 'dark' | 'warning' | 'muted';