0.0.225 • Published 9 months ago

remult-uikit v0.0.225

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

Demo: code sandbox

Remult-uikit

remult-uikit is a React UI library for developers working with the remult framework, enabling developers to build full composable UI's from scratch in minutes, and minimal effort, or integrate components (forms, views) into your already existing apps. Remult-uikit uses remult configurations across your frontend to ensure consistency.

Building on top of remult, remult-uikit offers:

  • better, consistent user experience on the frontend
  • consistency for data handling - display, validation
  • declarative way of building UI's

Quick start

1.

yarn add remult remult-uikit

npm add remult remult-uikit
  1. Install your preferred UI lib
  • currently supported: Material-UI V5
  1. Create your remult entity
@Entity<User>('users', {
  @Fields.uuid()
  id = ''

  @Fields.string({
    validate: [Validators.required, Validators.uniqueOnBackend],
  })
  email = ''

  @Fields.string()
  name = ''
})
  1. In your react code:
import { RemultForm } from 'remult-uikit'

const createUser = () => <RemultForm entity={User} />

Note

In order to enjoy the full features remult-uikit offers, you would need to add some boilerplate to the remult types, as remult does not yet supports everything (see more about customizing the remult types here)

Add an index.d.ts file to your project (make sure typescript sees this file through tsconfig.json)

declare module 'remult' {
  export interface FieldOptions<entityType, valueType> {
    required?: boolean
    hideOnCreate?: boolean
    select?: {
      options: { id: string | number; label: string }[]
      multiple?: boolean
      type?: 'select' | 'checkbox' | 'radiobox'
    }
  }
}

Now you can define everything you need in the entities files and it will be reflected in the frontend

Supported UI libraries

Material-UI V5

yarn add @emotion/react @emotion/styled @mui/icons-material @mui/material @mui/system @mui/x-data-grid @mui/x-data-grid-generator @mui/x-date-pickers

npm install @emotion/react @emotion/styled @mui/icons-material @mui/material @mui/system @mui/x-data-grid @mui/x-data-grid-generator @mui/x-date-pickers

Examples

import { Allow, Entity, Fields, Relations, Validators, remult } from 'remult'

@Entity<Organization>('organization')
export class Organization {
  @Fields.uuid()
  id = ''

  @Fields.string()
  name = ''
}

@Entity<User>('users', { caption: 'User' })
export class User {
  @Fields.uuid()
  id = ''

  @Fields.string({
    validate: [Validators.required, Validators.uniqueOnBackend],
    required: true,
  })
  email = ''

  @Fields.boolean({
    includeInApi: false,
  })
  isDisabled = false

  // Relation - if shows in form - will be automatically loaded and displayed as select component
  @Fields.string()
  organizationId = ''
  @Relations.toOne<User, Organization>(() => Organization, {
    field: 'organizationId',
  })
  organization?: Organization

  @Fields.string<User>({
    validate: (v) => {
      if (v.firstName.length < 3) {
        throw new Error('First name must be at least 3 characters long')
      }
    },
  })
  name = ''

  // By default, this will render a list of checkboxes
  @Fields.json<User>({
    validate: (row) => {
      if (row) {
        throw new Error('Need to select at least 1')
      }
    },
    select: {
      options: ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'].map((d) => ({
        id: d,
        label: d.toUpperCase(),
      })),
      multiple: true,
      // Add type to show this as a select component
      // type: 'select'
    },
    caption: 'Available Days',
  })
  availableDays = []

  // By default, this will render a radio group
  @Fields.integer<User>({
    select: {
      options: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((d) => ({
        id: d,
        label: d.toString() + ':00 HR',
      })),
      // Add type to show this as a select component
      // type: 'select',
    },
    caption: 'Working Hours Start',
  })
  workingHoursStart = 0

  // Hidden by default
  @Fields.createdAt()
  createdAt?: Date

  // Hidden by default
  @Fields.updatedAt()
  updatedAt?: Date
}
0.0.87

10 months ago

0.0.88

10 months ago

0.0.89

10 months ago

0.0.205

10 months ago

0.0.209

10 months ago

0.0.207

10 months ago

0.0.206

10 months ago

0.0.201

10 months ago

0.0.216

10 months ago

0.0.215

10 months ago

0.0.214

10 months ago

0.0.213

10 months ago

0.0.219

9 months ago

0.0.218

9 months ago

0.0.217

10 months ago

0.0.212

10 months ago

0.0.211

10 months ago

0.0.210

10 months ago

0.0.95

10 months ago

0.0.96

10 months ago

0.0.225

9 months ago

0.0.97

10 months ago

0.0.224

9 months ago

0.0.98

10 months ago

0.0.99

10 months ago

0.0.90

10 months ago

0.0.223

9 months ago

0.0.102

10 months ago

0.0.91

10 months ago

0.0.222

9 months ago

0.0.101

10 months ago

0.0.221

9 months ago

0.0.100

10 months ago

0.0.93

10 months ago

0.0.220

9 months ago

0.0.94

10 months ago

0.0.2

10 months ago

0.0.85

1 year ago

0.0.86

1 year ago

0.0.80

2 years ago

0.0.81

2 years ago

0.0.78

2 years ago

0.0.79

2 years ago

0.0.62

2 years ago

0.0.65

2 years ago

0.0.67

2 years ago

0.0.69

2 years ago

0.0.61

2 years ago

0.0.59

2 years ago

0.0.77

2 years ago

0.0.70

2 years ago

0.0.71

2 years ago

0.0.56

2 years ago

0.0.57

2 years ago

0.0.53

2 years ago

0.0.54

2 years ago

0.0.55

2 years ago

0.0.51

2 years ago

0.0.52

2 years ago

0.0.50

2 years ago

0.0.49

2 years ago

0.0.48

2 years ago

0.0.46

2 years ago

0.0.47

2 years ago

0.0.40

2 years ago

0.0.41

2 years ago

0.0.42

2 years ago

0.0.43

2 years ago

0.0.44

2 years ago

0.0.45

2 years ago

0.0.37

2 years ago

0.0.38

2 years ago

0.0.39

2 years ago

0.0.30

2 years ago

0.0.31

2 years ago

0.0.32

2 years ago

0.0.33

2 years ago

0.0.34

2 years ago

0.0.35

2 years ago

0.0.36

2 years ago

0.0.28

2 years ago

0.0.29

2 years ago

0.0.27

2 years ago

0.0.26

2 years ago

0.0.25

2 years ago