Skip to content

Commit

Permalink
adding some bootstrap classes
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Nov 20, 2023
1 parent b0c93c4 commit b78b1ae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
24 changes: 23 additions & 1 deletion packages/fastui-bootstrap/src/index.tsx
Original file line number Diff line number Diff line change
@@ -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') {
Expand All @@ -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':
Expand All @@ -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'
}
}
3 changes: 2 additions & 1 deletion packages/fastui/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b78b1ae

Please sign in to comment.