0.1.0-beta.15 • Published 4 years ago

@ludekarts/base-ui v0.1.0-beta.15

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

Basic UI Components for React projects


Basic Components

GlobalStyles

Wrapper component that provides all base-ui utility classes.

  import { GlobalStyles } from "@ludekarts/base-ui";

  const App = props => <GlobalStyles><App/></GlobalStyles>;

Props

Prop nameTypeDefaultDescription
fullCoverbooleanfalseExpands page body to cover entire screen

Available classes


CSS variables

Variable namevalue
--bui-focus-colorrgba(66, 153, 225, 0.6)
--bui-box-shadow0px 9px 9px -11px rgba(0, 0, 0, 0.5)
--bui-lift-shadow0px 23px 18px -21px rgba(0, 0, 0, 0.7)
--bui-space0.5rem
--bui-space-2x1rem
--bui-space-3x1.5rem
--bui-space-4x2rem

Flex modifiers

Class nameDescription
--flex-columnChanges flex display to column
--flex-row-reverseReverse elements oreder in flex row

Block modifiers

Class nameDescription
--stretchSet element width to 100%
--stretch-vSet element height to 100%
--stretch-blockDiplay as block element and set width to 100%
--expand-contentSet width of element children to 100%
--text-centerCenter text
--text-rightAlign text right
--text-leftAlign text left
--text-boldDisplay bold text
--text-italicDisplay italic text
--text-no-wrapDo not wrap text
--first-letter-capsCapitalize first letter

Spacing outside (margin)

Class nameDescription
--spaceSet margin to 0.5rem
--space-2xSet margin to 1rem
--space-3xSet margin to 1.5rem
--space-4xSet margin to 2rem
--space-tSet margin top to 0.5rem
--space-t-2xSet margin top to 1rem
--space-t-3xSet margin top to 1.5rem
--space-t-4xSet margin top to 2rem
--space-rSet margin right to 0.5rem
--space-r-2xSet margin right to 1rem
--space-r-3xSet margin right to 1.5rem
--space-r-4xSet margin right to 2rem
--space-bSet margin bottom to 0.5rem
--space-b-2xSet margin bottom to 1rem
--space-b-3xSet margin bottom to 1.5rem
--space-b-4xSet margin bottom to 2rem
--space-lSet margin left to 0.5rem
--space-l-2xSet margin left to 1rem
--space-l-3xSet margin left to 1.5rem
--space-l-4xSet margin left to 2rem

Spacing inset (padding)

Class nameDescription
--space-iSet padding of 0.5rem
--space-2x-iSet padding of 1rem
--space-3x-iSet padding of 1.5rem
--space-4x-iSet padding of 2rem
--space-t-iSet padding top of 0.5rem
--space-t-2x-iSet padding top of 1rem
--space-t-3x-iSet padding top of 1.5rem
--space-t-4x-iSet padding top of 2rem
--space-r-iSet padding right of 0.5rem
--space-r-2x-iSet padding right of 1rem
--space-r-3x-iSet padding right of 1.5rem
--space-r-4x-iSet padding right of 2rem
--space-b-iSet padding bottom of 0.5rem
--space-b-2x-iSet padding bottom of 1rem
--space-b-3x-iSet padding bottom of 1.5rem
--space-b-4x-iSet padding bottom of 2rem
--space-l-iSet padding left of 0.5rem
--space-l-2x-iSet padding left of 1rem
--space-l-3x-iSet padding left of 1.5rem
--space-l-4x-iSet padding left of 2rem

Push content in flex containers (margin)

Class nameDescription
--push-topSet margin bottom to auto
--push-leftSet margin right to auto
--push-rightSet margin left to auto
--push-bottomSet margin top to auto

Verical flex alignment

Class nameAliasDescription
--v-start--stack-startAlign content to the TOP of the element
--v-end--stack-endAlign content to the BOTTOM of the element
--v-stretch--stack-stretchStretch content vertically
--v-center--stack-centerAlign content to the CENTER of the element

Horizontal flex alignment

Class nameAliasDescription
--h-start--rail-startAlign content to the SATRT of the element
--h-end--rail-endAlign content to the END of the element
--h-center--rail-centerAlign content to the CENTER of the element
--h-spread--rail-spreadSpread content to the sides of the element
--h-evenly--rail-evenlySpread content to evenly across the element
--h-around--rail-aroundSpread content with wcen space between inside the element

|

Default focus

Class nameDescription
--focusableAdd default focus behaviour to the element

Cover Link

Class nameDescription
--cover-link > a.--linkSets element postion to relative and changes interlan <a/> tag with --link class into "cover glass"

Text

Component for convinient text formatting.

  import { Text } from "@ludekarts/base-ui";

  . . .

  <Text as="h1" color="red" size="1.4em">This is h1 tag</Text>

Props

Prop nameTypeDefaultDescription
asstringspanDisplay as given element
lhstringundefinedLine height
fontstringundefinedFont family
sizestringundefinedFont size
weightstringundefinedFont weight
colorstringundefinedText color
spacingstringundefinedMargin
paddingstring0Padding
transformstringfalseText transform
ellipsisbooleanfalseCrop text with ellipsis
blockbooleanfalseDisplay as block

Form

Regular form with customized onSubmit handler with utilities for handling form data.

  import { Form } from "@ludekarts/base-ui";

  . . .

  const handleSubmit = data => {
    // data: object with all input fields names and their values e.g: { inputName: inputValue }.
  };

  <Form onSubmit={handleSubmit}>...</Form>

Props

Prop nameTypeDefaultDescription
childrennodenullComponent children
onSubmitfunctionundefinedCallback fn called when user submits data
includeCheckStatusbooleanfalseBy default only selected checkboxes will appear in onSubmit handlers data. If set to true all checkboxes will report their current check-status.

Static helpers

Helper nameDescription
Form.formInputsToObject( formRef, { includeCheckStatus: fasle } )Internaly used to transform form's data into object
Form.hardFormReset( formRef, { resetValue: false } )Allows to imperatively set all checkbox values to given resetValue

Badge

Rounded badge.

  import { Badge } from "@ludekarts/base-ui";

  . . .

  <Badge>20</Badge>

Props

Prop nameTypeDefaultDescription
mnwstring3remMinimal badge width
colorstring#CCCCCCBackground color
justifystringcenterContent justify (flex)

Interactive

Collapse

Animated container that can expand on it's content.

  import { Collapse } from "@ludekarts/base-ui/interactive";

  . . .

  const [showCollapse, toggleCollapse] = useState(false);

  <Collapse open={showCollapse} mnh={36}>Lorem ipsum dolor sit ammet...</Collapse>

Props

Prop nameTypeDefaultDescription
openbooleanfalseCurrent state of collapse container. Is external.
mxhnumberundefinedMaximal height of the container
mnhnumberundefinedMinimal height of the container

Slider

Container that slides its content horizontally or vertically.

  import { Slider } from "@ludekarts/base-ui/interactive";

  . . .

  const [activeSlide, setActiveSlide] = useState(0);

  <Wrapper styles={{width: "200px", height: "200px", position: "relative"}}>
    <Slider activeIndex={activeSlide} variant="vertical" loop>
      <div>SLIDE 1</div>
      <div>SLIDE 2</div>
      <div>SLIDE 3</div>
      <div>SLIDE 4</div>
      <div>SLIDE 5</div>
    </Slider>
  </Wrapper>

Props

Prop nameTypeDefaultDescription
activeIndexnumber0Currently displayed slide
variantstringhorizontalAnimation: horizontal or vertical
loopbooleanfalseMake slides loops form last to first an back
fitHeightbooleanfalseFit Slider height to its content

NOTE:

By default Slider expands to fill its container. You need to define the dimensions for the container.

BreakpointClass

Switches classes base on given brakpoint.

  import { BreakpointClass } from "@ludekarts/base-ui/interactive";

  . . .
  
  <BreakpointClass breakpoint="(max-width: 980px)" beforeClass="class-a" afterClass="class-b">
    <div>Element 1</div>
    <div>Element 2</div>
  </BreakpointClass>

Props

Prop nameTypeDefaultDescription
breakpointstringREQUIREDMedia brekpoint which changes the clsses
beforeClassstringList of classes before applying breakpoint
afterClassstringList of classes after applying breakpoint

Buttons

Basic

Simple, regular button.

  import { Button } from "@ludekarts/base-ui/buttons";

  . . .

  <Button>Hello</Button>

Props

Prop nameTypeDefaultDescription
sizestringmdButton size, one of: lg, md, sm
textstringinheritText color
colorstring#DDDDDDBackground color
radiusstring0.2emButton rounded corner
typestringbuttonButton type. To use thie component as a Submin button we need to specify submit type
disabledboolfalseDisable state
inversebool/numberundefinedInverse colors

NOTE:

All buttons have their boolean attributes defined as bool/number type. This allows to convert a button into Link tag from react-router-dom. When used as Link set boolean attribute (e.g. inverse) should ne set to numeric value: 1/0.

Underline

Button with animated underline .

  import { Underline } from "@ludekarts/base-ui/buttons";

  . . .

  <Underline>Hello</Underline>

Props

Prop nameTypeDefaultDescription
sizestringmdButton size, one of: lg, md, sm
textstring#000000Text color
colorstring#999999Background color
typestringbuttonButton type. To use thie component as a Submin button we need to specify submit type
disabledboolfalseDisable state
activebool/numberundefinedActive state
inversebool/numberundefinedInverse colors
outlineFocusbool/numberundefinedApply outline focus
.activeclassNameSame as active prop
.active-inverseclassNameInverse colors of active state

Ghost

Button with thick border empty inside.

  import { Ghost } from "@ludekarts/base-ui/buttons";

  . . .

  <Ghost>Hello</Ghost>

Props

Prop nameTypeDefaultDescription
sizestringmdButton size, one of: lg, md, sm
textstringinheritText color
colorstring#999999Background color
typestringbuttonButton type. To use thie component as a Submin button we need to specify submit type
disabledboolfalseDisable state
activebool/numberundefinedActive state
inversebool/numberundefinedInverse colors
uppercasebool/numberundefinedUppercase text
roundedbool/numberundefinedSet rounded corners
.no-text-bgclassNameDisables text color background

Highlight

Button for highlight icons or glyphs.

  import { Highlight } from "@ludekarts/base-ui/buttons";

  . . .

  <Highlight>+</Highlight>

Props

Prop nameTypeDefaultDescription
sizestringmdButton size, one of: lg, md, sm
colorstringrgba(0, 0, 0, 0.15)Background color
activeTextstringfalseText color
squarebool/numberundefinedDo not use rounded corners
outlinebool/numberundefinedShow outline
activebool/numberundefinedActive state

Switch

Checkbox/Radio component with visual appearance of dot slider.

  import { Switch } from "@ludekarts/base-ui/buttons";

  . . .

  <Switch name="mySwitch" size="lg" color="red" offColor="gray" />

Props

Prop nameTypeDefaultDescription
namestringREQUIREDInput name
idstringsame as nameInput ID
typecheckbox/radiocheckboxInput type
sizestringmdButton size, one of: lg, md, sm
squaredboolfalseUse square corners
colorstringfalseBackground color
offColorstringfalseBackground color for OFF state

Checkbox

Checkbox/Radio component with visual appearance of checkbox with a checkmark inside.

  import { Checkbox } from "@ludekarts/base-ui/buttons";

  . . .

  <Checkbox name="c3" color="red" defaultChecked />

Props

Prop nameTypeDefaultDescription
namestringREQUIREDInput name
idstringsame as nameInput ID
typecheckbox/radiocheckboxInput type
bgboolfalseBackground color
colorboolfalseCheckmark color
roundedboolfalseUse rounded corners

Close

Internally used close button for panels.

  import { Close } from "@ludekarts/base-ui/buttons";

  . . .

  <Close onClick={() => {}} size="2em" />

Props

Prop nameTypeDefaultDescription
textstringinheritIcon color
colorstring#EEEEEEBackground color
sizestring1.5emIcon size
typestringbuttonButton type
spacingstring3pxMargin around icon
focusColorstringrgba(66, 153, 225, 0.6)Focus outline color

Layout

Container

Description

  import { Container } from "@ludekarts/base-ui/layout";

  . . .

  <Container mxw="1200px">
    Content
  </Container>

Props

Prop nameTypeDefaultDescription
mxwstring78remMaximal container width
offsetTopstring2remOffset from the top (margin-top)
spacingstring0 1.5em"Inside spacing (padding)

Stack

Arranges content items one under another.

  import { Stack } from "@ludekarts/base-ui/layout";

  . . .

  <Stack breakpoint="14rem">
    <div>Item</div>
    <div>Item</div>
    <div>Item</div>
    ...
  </Stack>

Props

Prop nameTypeDefaultDescription
gapstring1emSpace between items
mxwbool/numberundefinedSets max-width range for media query. By default Stack breaks at min-width
breakpointstringundefinedMin-width to break into rail layout

Rail

Arranges content items one next to another.

  import { Rail } from "@ludekarts/base-ui/layout";

  . . .

  <Rail gap="0.5em">
    <div>Item</div>
    <div>Item</div>
    <div>Item</div>
    ...
  </Rail>

Props

Prop nameTypeDefaultDescription
gapstring1emSpace between items
mnwbool/numberundefinedSets min-width range for media query. By default Stack breaks at max-width
breakpointstringundefinedMax-width to break into stack layout
wrapContentbool/numberundefinedAllows overflow item to wrap inside container

NOTE:

Most effective usage of this component can be achieved with accompaniment of Vertical & Horizontal Alignment from <Global Styles/> component.

Grid

Organize content in dynamic grid.

  import { Grid } from "@ludekarts/base-ui/layout";

  . . .

  <Grid>
    <div>Cell</div>
    <div>Cell</div>
    <div>Cell</div>
    <div>Cell</div>
    ...
  </Grid>

Props

Prop nameTypeDefaultDescription
gapstring1emSpace between cells
sizestring16remMinimal cell size
alignstringcenterCell's content alignment

Columns

Displays children in columns.

  import { Columns } from "@ludekarts/base-ui/layout";

  . . .

  <Columns>
    <div>1 column</div>
    <div>2 column</div>
    ...
  </Columns>

Props

Prop nameTypeDefaultDescription
gapstring1emSpace between columns
minSizestring14remMinimal one column size

Cover

Covers parent container.

  import { Cover, Space } from "@ludekarts/base-ui/layout";

  . . .

  <Cover className="--v-center --h-center">
    <Space space="0 0 0 auto">Top right corner</Space>
    <Space space="auto">Center content</Space>
    <Space space="0 auto 0 0">Bottom left corner</Space>
  </Cover>

Sidebar

Displays children (only 2) as a sidebar and main content.

  import { Sidebar } from "@ludekarts/base-ui/layout";

  . . .

  <Sidebar>
    <aside>Sidebar content</aside>
    <main>Main content</main>
  </Sidebar>

Props

Prop nameTypeDefaultDescription
gapstring1emSpace between sidebar nad content
breakAtstring50%Minial content width
sideWidthstring15emSidebar width
rightbooleanfalsePlaces sidebar on the right side

Space

Manipulates negative space.

  import { Space } from "@ludekarts/base-ui/layout";

  . . .

  <Space />

  <Space>
    Content
  </Space>

Props

Prop nameTypeDefaultDescription
spacestring1em 0 0Amount of negative space (margin/padding) in given units. By default uses margin
insetbooleanfalseIf set to true negative space is calculated as padding
minmaxstringminMedia query "direction" min-width or max-width
breakpointstringundefinedMedia query breakpoint
spaceBeforestringundefinedSpace before applying breakpoint. Takes precedence of space prop
spaceAfterstringundefinedSpace after applying breakpoint. Takes precedence of space prop

Media

Image

Displats image with additional fallback error to image placeholder.

  import { Image } from "@ludekarts/base-ui/media";

  . . .

  <Image src="https://url/to/image.jpg" alt="This is image description" />

Props

Prop nameTypeDefaultDescription
srcstringfalseImage source
altstringfalseAccessible image description
sizestringfalseImage width & height
widthstring100%Image width
heightstringautoImage height

Avatar

Image with same width and height.

  import { Avatar } from "@ludekarts/base-ui/media";

  . . .

  <Avatar src="https://url/to/image.jpg" size="2em" />

Props

Prop nameTypeDefaultDescription
sizestring3remAvatar width & height
roundedstring50%Amount of corners rounding

AspectRatio

Renders container size with given ratio

  import { AspectRatio } from "@ludekarts/base-ui/media";

  . . .

  <AspectRatio>
    Content
  </AspectRatio>

Props

Prop nameTypeDefaultDescription
ratiostringvideoOne of the value form table below
turnOffAtstringundefinedMax-width to turn off scaling

Ratios

Prop value
video
16:9
8:5
3:2
4:3
1:1
square

Panels

Overlay

Black animated panel that covers entire screen.

  import { Overlay } from "@ludekarts/base-ui/panels";

  . . .

  <Overlay>
    Content
  </Overlay>

Props

Prop nameTypeDefaultDescription
openboolfalseOverlay open state
topnumber0Top offset
tintnumber0.9Transparency
zIndexnumber1500Z-index
delayInnumber0Delay for in-animation
delayOutnumber0Delay for out-animation
durationnumber0.3Animation duration

Drawer

Animated panels that slides-in from right side of the screen.

  import { Drawer } from "@ludekarts/base-ui/panels";

  . . .

  const [showDrawer, toggleDrawer] = useState(false);

  <Drawer open={showDrawer} onClose={() => toggleDrawer(false)}>
    Content
  </Drawer>

Props

Prop nameTypeDefaultDescription
openboolfalseDrawer open state
nestedboolfalseSet to true if drawer is nested in another drawer
noOverlayboolfalseToggles background Overlay component
topstring0Top offset
widthstring18remDeawer width
onClosefunctionundefinedOn close callback. If defined Close button will appear in the drawer

Modal

Description

  import { Modal } from "@ludekarts/base-ui/panels";

  . . .

    const [showModal, togglwModal] = useState(false);

  <Modal open={showModal} onClose={() => togglwModal(false)}>
    Content
  </Modal>

Props

Prop nameTypeDefaultDescription
openboolfalseModal open state
onClosefunctionundefinedOn close callback. If defined Close button will appear in the modal

Dropdown

Animated dropdown panel that can be triggered by adding data-bui-dropdown-target attribute with a dropdownName to any element.

  import { Dropdown } from "@ludekarts/base-ui/panels";

  . . .

  <button data-bui-dropdown-target="dropdownName">Toggle my dropdown</button>

  <Dropdown name="dropdownName" onToggle={ toggleState => {} } autoHide>
    Content
  </Dropdown>

Props

Prop nameTypeDefaultDescription
namestringREQUIREDUnique name that allow to identify target dropdown
onTogglefunctionundefinedCallback fn called with current toggleState
autoHidebooleanfasleIf set to true dropdown will automatically close after user click

Progress

In progress ...

0.1.0-beta.15

4 years ago

0.1.0-beta.14

4 years ago

0.1.0-beta.12

4 years ago

0.1.0-beta.11

4 years ago

0.1.0-beta.13

4 years ago

0.1.0-beta.10

4 years ago

0.1.0-beta.9

4 years ago

0.1.0-beta.7

4 years ago

0.1.0-beta.8

4 years ago

0.1.0-beta.6

4 years ago

0.1.0-beta.5

4 years ago

0.1.0-beta.4

4 years ago

0.1.0-beta.3

4 years ago

0.1.0-beta.2

4 years ago

0.1.0-beta.1

4 years ago