From b78b1ae86800d5cc599a27a49353df159b81269f Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Mon, 20 Nov 2023 16:24:47 +0000 Subject: [PATCH] adding some bootstrap classes --- packages/fastui-bootstrap/src/index.tsx | 24 +++++++++++++++++++++++- packages/fastui/src/index.tsx | 3 ++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/fastui-bootstrap/src/index.tsx b/packages/fastui-bootstrap/src/index.tsx index 6f13c97d..01e7e721 100644 --- a/packages/fastui-bootstrap/src/index.tsx +++ b/packages/fastui-bootstrap/src/index.tsx @@ -1,5 +1,7 @@ import { ClassNameGenerator, CustomRender } from 'fastui' +import type { FormFieldProps } from 'fastui' + export const customRender: CustomRender = (props) => { const { type } = props if (type === 'DisplayPrimitive') { @@ -10,7 +12,7 @@ export const customRender: CustomRender = (props) => { } } -export const classNameGenerator: ClassNameGenerator = (props) => { +export const classNameGenerator: ClassNameGenerator = (props, subElement) => { const { type } = props switch (type) { case 'Page': @@ -23,5 +25,25 @@ export const classNameGenerator: ClassNameGenerator = (props) => { return 'btn btn-primary' case 'Table': return 'table table-striped' + case 'FormFieldInput': + case 'FormFieldCheckbox': + case 'FormFieldSelect': + case 'FormFieldFile': + return formClassName(props, subElement) + } +} + +function formClassName(props: FormFieldProps, subElement?: string) { + switch (subElement) { + case 'input': + return props.error ? 'is-invalid form-control' : 'form-control' + case 'select': + return 'form-select' + case 'label': + return 'form-label' + case 'error': + return 'invalid-feedback' + default: + return 'mb-3' } } diff --git a/packages/fastui/src/index.tsx b/packages/fastui/src/index.tsx index 85d9f09e..e967eda0 100644 --- a/packages/fastui/src/index.tsx +++ b/packages/fastui/src/index.tsx @@ -6,10 +6,11 @@ import { ClassNameContext, ClassNameGenerator } from './hooks/className' import { ErrorContextProvider, ErrorDisplayType } from './hooks/error' import { CustomRender, CustomRenderContext } from './hooks/customRender' import { FastProps } from './components' +import { FormFieldProps } from './components/FormField' import { DisplayChoices } from './display' import { DevReloadProvider } from './hooks/dev' -export type { ClassNameGenerator, CustomRender, ErrorDisplayType, FastProps, DisplayChoices } +export type { ClassNameGenerator, CustomRender, ErrorDisplayType, FastProps, DisplayChoices, FormFieldProps } export interface FastUIProps { rootUrl: string