From c84882da4ec4bd2384dea7cc173dfaece8492619 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Fri, 1 Dec 2023 14:04:52 +0300 Subject: [PATCH] apps/web: use grid in render-rows.tsx --- .../Calculation/lib/render-rows.tsx | 37 ++++++------------- packages/ui/grid.ts | 29 ++++++++++++++- packages/ui/utils.ts | 5 ++- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/apps/web/Components/Calculation/lib/render-rows.tsx b/apps/web/Components/Calculation/lib/render-rows.tsx index 2a879f6..8132344 100644 --- a/apps/web/Components/Calculation/lib/render-rows.tsx +++ b/apps/web/Components/Calculation/lib/render-rows.tsx @@ -3,13 +3,10 @@ import elementsRender from '../config/elements-render'; import type { Elements as ActionElements } from '../config/map/actions'; import type { Elements as ValuesElements } from '../config/map/values'; import { Divider } from 'ui/elements'; -import type { BoxProps } from 'ui/grid'; -import { Box } from 'ui/grid'; +import type { GridProps } from 'ui/grid'; +import { Grid } from 'ui/grid'; -export type ElementsRow = [ - elements: Array, - style?: BoxProps['sx'] -]; +export type ElementsRow = [elements: Array, style?: GridProps]; type DividerRow = { title: string }; export type FormTabRows = Array; @@ -19,23 +16,20 @@ function renderFormRows(rowsConfig: FormTabRows) { if (Array.isArray(row)) { const [elements, style] = row; const renderedElements = elements.map((elementName) => { - const render = elementsRender[elementName]?.render; + const Render = elementsRender[elementName]?.render; - return render({}); + return ; }); return ( - {renderedElements} - + ); } @@ -44,16 +38,7 @@ function renderFormRows(rowsConfig: FormTabRows) { return {title}; }); - return ( - - {rows} - - ); + return {rows}; } export default renderFormRows; diff --git a/packages/ui/grid.ts b/packages/ui/grid.ts index 20a04b5..9c00fbb 100644 --- a/packages/ui/grid.ts +++ b/packages/ui/grid.ts @@ -1,5 +1,6 @@ import type { Theme } from './utils'; import { getStyles } from './utils'; +import type { PropsWithChildren } from 'react'; import styled from 'styled-components'; export type { BoxProps, FlexProps } from 'rebass/styled-components'; @@ -9,7 +10,33 @@ type WithArrayType = { [K in keyof T]: Array | T[K]; }; -export type GridProps = WithArrayType; +type GridSelectedProps = Pick< + HTMLDivElement['style'], + | 'alignItems' + | 'columnGap' + | 'gap' + | 'grid' + | 'gridArea' + | 'gridAutoColumns' + | 'gridAutoFlow' + | 'gridAutoRows' + | 'gridColumn' + | 'gridColumnEnd' + | 'gridColumnStart' + | 'gridRow' + | 'gridRowEnd' + | 'gridRowStart' + | 'gridTemplate' + | 'gridTemplateAreas' + | 'gridTemplateColumns' + | 'gridTemplateRows' + | 'justifyContent' + | 'justifyItems' + | 'placeContent' + | 'placeItems' + | 'rowGap' +>; +export type GridProps = Partial> & PropsWithChildren; export const Grid = styled.div` display: grid; diff --git a/packages/ui/utils.ts b/packages/ui/utils.ts index 28fa02b..95c33ee 100644 --- a/packages/ui/utils.ts +++ b/packages/ui/utils.ts @@ -8,15 +8,18 @@ function min(breakpoint: string, style: string) { }`; } export function getStyles(props: Record, theme: Theme) { - const cleanProps = omit(props, ['children']); + const cleanProps = omit(props, ['children', 'id', 'key', 'className']); + return (Object.keys(cleanProps) as Array).map((name) => { const styleValues = cleanProps[name]; if (Array.isArray(styleValues)) { const [firstStyle, ...values] = styleValues; + return theme.breakpoints .map((breakpoint, i) => { if (!values[i]) return undefined; const style = `${dash(name)}:${values[i]}`; + return min(breakpoint, style); }) .concat([`${dash(name)}:${firstStyle};`])