1.0.0-rc.23 • Published 11 months ago

@bodiless/ui v1.0.0-rc.23

Weekly downloads
108
License
Apache-2.0
Repository
github
Last release
11 months ago

@bodiless/ui

This package contains shared UI elements for the default Bodiless edit interface. UI elements which are used by more than one Bodiless package should be defined here.

Exposing an "injectible" UI.

In general, any Bodiless component which exposes an edit interface or other administrative UX should allow injection of the UI elements it needs by accepting a ui prop. The value for this prop should be a keyed set of components. The structure of this object should be defined by a UI interface. For example, consider a component which renders a message:

type FullUI = {
  Wrapper: ComponentType<HTMLProps<HTMLDivElement>> | string,
  Text: ComponentType<HTMLProps<HTMLSpanElement>> | string,
  DismissButton: ComponentType<HTMLProps<HTMLButtonElement>> | string,
  Icon: ComponentType<HTMLProps<HTMLSpanElement>> | string.
};

export type UI = Partial<FullUI>;

export type Props = {
  message: string,
  icon: string,
  ui?: UI,
};

const defaultUI: FullUI = {
  Wrapper: 'div',
  Text: 'span',
  DismissButton: 'button',
  Icon: 'i',
};

const getUI = (ui: UI) => ({ ...defaultUI, ...ui });

export const MessageBox = ({ message, icon, ui }) => {
  const { Wrapper, Text, DismissButton, Icon } = getUI(ui);
  return (
    <Wrapper>
      <Icon>{icon}</Icon>
      <Text>{message}</Text>
      <DismissButton />
    </Wrapper>
  );
};

Implementing the UI

A library can now implement the UI by wrapping the "clean" version of the component with a version which provides styled UI elements (the following example uses the fclasses library to style using tailwind classes):

import { stylable, addClasses } from '@bodiless/fclasses';
import { MessageBox as CleanMessageBox, Props } from 'messagebox';

const Div = stylable<HTMLProps<HTMLDivElement>>('div');
const Span = stylable<HTMLProps<HTMLSpanElement>>('span');

const ui: UI = {
  Wrapper: addClasses('bg-black text-white')(Div);
  Icon: addClasses('block material-icon text-xl')(Span);
};

export const MessageBox: FC<Props> = props = <CleanMessageBox {...props} ui={ui} />;

Note - here we only provide overrides for two out of the four elements. The others will fall back to their defaults.

Default UI

Each package in the bodiless ecosystem should have a corresponding -ui package which exports a default implementation of the UI for any admin or editorial interfaces it supplies. Wherever possible, this package should make use of shared elements from this basic bodiless-ui package.

Components

<Spinner />

Adds the spinner, which centers itself based on its container's dimensions.

You can also override the width and height if you want a bigger or smaller spinner by adding more style rules to the exposed .bodiless-spinner class here.

Properties

NameTypeDefaultDescription
colorStringThe css class name, used to control a color of the spinner.

Usage:

import { Spinner } from '@bodiless/ui';
import React, { Component } from 'react';

export default class Example extends Component {
  render() {
  return (
      <div>
        <Spinner color="bl-bg-gray" />
      </div>
    );
  }
}

Bodiless classes

Bodiless uses tailwind for the styling of bodiless editor. A site built with this tool also uses tailwind for site styling. This leads to two tailwind configs in use. Bodiless tailwind config resides in packages/bodiless-ui/bodiless.tailwind.config.js. We have prefaced it with the prefix bl- to isolate styling needed for the Bodiless editor. The site’s tailwind.config.js resides at site level (i.e. examples/test-site or examples/starter) and this is also built. Therefore we introduce two css files within the edit mode: prefixed (bs-) for bodiless editor and non-prefixed for the site. The static mode would only serve the non-prefixed (at this point in time it is a future enhancement to remove the bodiless editor from static build).

The recommended guideline is to prefix any bodiless editor styling with bl- and any site level styling without the prefix to continue this separation.

Technical Details

The default tailwind.config uses rem based grid styling system for paddings, margins, etc. While rems may be good for font-size it brings some level of inconsistency when it used for margins, paddings, widths, etc. since it is based on the body font-size. In this PR we configured our bodiless.tailwind.config to use px instead of rem. It has a basic 5px grid system ( all margins, paddings, widths, etc. are measured with increments of 5 ) and can be extended as we need.

Spacing class names are prefixed with grid-{number} prefix where {number} represents a multiples of 5s. For example .bl-m-grid-2 would be margin: 10px.

This grid system is broken down into multiple logical pieces to minimize the 'css' file size since not all of the tailwind elements might need all of the values from the grid system. These parts include:

  • defaultGrid - For general use throughout the app.
  • xlGrid - Extra Large values that are handy when we work with max-width, max-height etc.
  • negativeGrid - Useful when we need negative margins or with top, bottom, left, right styles.
  • percentGrid - For the places where we need % values. (bl-w-full --> width: 100%).

Use Case

We may not want to use all of the values from this grid system in certain tailwind elements to save some file kb. For example, we may not need the defaultGrid and negativeGrid values for maxWidth since these are small so we only include xlGrid and/or percentGrid for maxWidth:

maxWidth: {
  ...xlGrid, ...percentGrid,
}, 

Class Name Examples

  • .bl-p-grid-1 --> padding: 5px; (defaultGrid values)
  • .bl-mt-xl-grid-0 --> margin-top: 100px; (xlGrid values)
  • .bl--top-grid-4 --> top: -20px; (negativeGrid values)
  • .bl-w-full --> width: 100%; (percentGrid values )
1.0.0-rc.42

11 months ago

1.0.0-rc.41

11 months ago

1.0.0-rc.40

11 months ago

1.0.0-rc.39

11 months ago

1.0.0-rc.38

11 months ago

1.0.0-rc.35

1 year ago

1.0.0-rc.34

1 year ago

1.0.0-rc.37

1 year ago

1.0.0-rc.36

1 year ago

1.0.0-rc.24

1 year ago

1.0.0-rc.28

1 year ago

1.0.0-rc.27

1 year ago

1.0.0-rc.26

1 year ago

1.0.0-rc.25

1 year ago

1.0.0-rc.29

1 year ago

1.0.0-rc.31

1 year ago

1.0.0-rc.30

1 year ago

1.0.0-rc.33

1 year ago

1.0.0-rc.32

1 year ago

1.0.0-rc.23

1 year ago

1.0.0-rc.19

2 years ago

1.0.0-rc.18

2 years ago

1.0.0-rc.20

2 years ago

1.0.0-rc.22

2 years ago

1.0.0-rc.21

2 years ago

1.0.0-rc.17

2 years ago

1.0.0-rc.16

2 years ago

1.0.0-rc.15

2 years ago

1.0.0-rc.13

2 years ago

1.0.0-rc.12

2 years ago

1.0.0-rc.11

2 years ago

1.0.0-rc.10

2 years ago

1.0.0-rc.14

2 years ago

1.0.0-rc.9

2 years ago

1.0.0-rc.7

2 years ago

1.0.0-rc.8

2 years ago

1.0.0-rc.5

2 years ago

1.0.0-rc.6

2 years ago

1.0.0-rc.3

2 years ago

1.0.0-rc.4

2 years ago

1.0.0-rc.2

2 years ago

1.0.0-rc.1

2 years ago

1.0.0-beta.11

2 years ago

1.0.0-beta.12

2 years ago

1.0.0-beta.10

2 years ago

1.0.0-beta.17

2 years ago

1.0.0-beta.18

2 years ago

1.0.0-beta.15

2 years ago

1.0.0-beta.16

2 years ago

1.0.0-beta.2

2 years ago

1.0.0-beta.3

2 years ago

1.0.0-beta.4

2 years ago

1.0.0-beta.5

2 years ago

1.0.0-beta.0

2 years ago

1.0.0-beta.1

2 years ago

1.0.0-beta.6

2 years ago

1.0.0-beta.7

2 years ago

1.0.0-beta.8

2 years ago

1.0.0-beta.9

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.7

2 years ago

0.3.2

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.1

2 years ago

0.3.0

3 years ago

0.2.10

3 years ago

0.1.2

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.72

3 years ago

0.0.71

3 years ago

0.0.70

3 years ago

0.0.69

3 years ago

0.0.68

3 years ago

0.0.67

3 years ago

0.0.66

3 years ago

0.0.65

3 years ago

0.0.64

3 years ago

0.0.63

3 years ago

0.0.62

3 years ago

0.0.61

3 years ago

0.0.60

3 years ago

0.0.59

4 years ago

0.0.58

4 years ago

0.0.57

4 years ago

0.0.56

4 years ago

0.0.55

4 years ago

0.0.54

4 years ago

0.0.53

4 years ago

0.0.52

4 years ago

0.0.51

4 years ago

0.0.50

4 years ago

0.0.49

4 years ago

0.0.48

4 years ago

0.0.47

4 years ago

0.0.45

4 years ago

0.0.46

4 years ago

0.0.44

4 years ago

0.0.43

4 years ago

0.0.41

4 years ago

0.0.42

4 years ago

0.0.40

4 years ago

0.0.39

4 years ago

0.0.38

4 years ago

0.0.37

4 years ago

0.0.36

4 years ago