Skip to content

Tailwind migration

Starting with v4 of OpenCloud Web and the design-system, the custom utility classes and variables have been removed in favor of Tailwind. We made this decision because great CSS frameworks like Tailwind are already out there and we feel like there is no need to reinvent the wheel. We want as little custom code as possible to be able to develop fast and with high quality while providing a well documented developer experience. The latter is given via Tailwind's extensive documentation.

The following guide shows how to migrate your application or extension to v4 of OpenCloud Web and its design-system.

Utility classes

Spacing

OC utility classTailwind utility class
oc-m-xsm-1
oc-m-sm-2
oc-m-mm-4
oc-m-lm-6
oc-m-xlm-12
oc-m-xxlm-24
oc-mm-4
oc-m-rmm-0

The same goes for the padding utility classes (replace m with p).

Text size

OC utility classTailwind utility class
oc-text-xsmalltext-xs
oc-text-smalltext-sm
oc-text-mediumtext-base
oc-text-largetext-lg
oc-text-xlargetext-xl

Font weight

OC utility classTailwind utility class
oc-font-semiboldfont-semibold
oc-text-boldfont-semibold

Text alignment

OC utility classTailwind utility class
oc-text-centertext-center
oc-text-lefttext-left
oc-text-righttext-right

Word breaks and truncation

OC utility classTailwind utility class
oc-text-truncatetruncate
oc-text-nowrapwhitespace-nowrap

Line height

The line-height gets determined by the given text- class. However, it can also be adjusted separately via the leading- classes (see https://tailwindcss.com/docs/line-height#setting-independently).

Text decoration

For text-decoration we didn't have a utility class. When a decoration is needed on hover, just use hover:underline. Disabling the underline is usually not needed since this is already done via the Tailwind preflight.

Colors

The theme color roles now exist as Tailwind variables and can be used like so: bg-role-primary, text-role-on-primary. This also supports variations, e.g. hover:text-role-on-primary or bg-role-primary/50.

These oc-helper classes are now redundant:

OC utility classTailwind utility class
oc-text-mutedtext-role-on-surface-variant
oc-text-errortext-role-on-error

Borders

OC utility classTailwind utility class
oc-borderborder
oc-roundedrounded-sm

For more variants, please refer to https://tailwindcss.com/docs/border-width.

Width

OC utility classTailwind utility class
oc-width-1-1w-full
oc-width-1w-full
oc-width-largew-lg
oc-width-mediumw-sm
oc-width-smallw-xs
oc-width-expandflex-1
oc-width-autow-auto

Height

OC utility classTailwind utility class
oc-height-1-1h-full
oc-height-viewporth-screen
oc-height-smallh-[150px]
oc-height-mediumh-[300px]
oc-height-largeh-[450px]

Display

OC utility classTailwind utility class
oc-display-blockblock
oc-display-inline-blockinline-block

Flex

OC utility classTailwind utility class
oc-flexflex
oc-flex-inlineinline-flex
oc-flex-leftjustify-start
oc-flex-centerjustify-center
oc-flex-rightjustify-end
oc-flex-betweenjustify-between
oc-flex-aroundjustify-around
oc-flex-topitems-start
oc-flex-middleitems-center
oc-flex-bottomitems-end
oc-flex-stretchitems-stretch
oc-flex-rowflex-row
oc-flex-row-reverseflex-row-reverse
oc-flex-columnflex-col
oc-flex-column-reverseflex-col-reverse
oc-flex-nowrapflex-nowrap
oc-flex-wrapflex-wrap
oc-flex-wrap-reverseflex-wrap-reverse
oc-flex-1flex-1

Overflow

OC utility classTailwind utility class
oc-overflow-hiddenoverflow-hidden
oc-overflow-autooverflow-auto
oc-text-overflowmax-w-full and/or overflow-hidden

Position

OC utility classTailwind utility class
oc-position-relativerelative
oc-position-fixedfixed
oc-position-absoluteabsolute
oc-position-centerabsolute top-[50%] left-[50%] transform-[translate(-50%, -50%)]
oc-position-center-rightabsolute top-[50%] right-0 transform-[translateY(-50%)]
oc-position-bottom-centerabsolute left-[50%] bottom-0 transform-[translateX(-50%)]
oc-position-coverabsolute inset-0

Visibility

OC utility classTailwind utility class
oc-invisible-srsr-only
oc-invisibleinvisible
oc-hiddenhidden

Cursor

OC utility classTailwind utility class
oc-cursor-pointercursor-pointer

Box-shadow

OC utility classTailwind utility class
oc-box-shadow-mediumshadow-md/20

Custom CSS

The philosophy of Tailwind is to use utility classes as much as possible. However, in rare occasions where you need to write custom CSS, it's recommended to put your styles into Tailwind's layer system.

Example

html
<style>
  @reference '@opencloud-eu/design-system/dist/tailwind.css';

  @layer components {
    .element {
      @apply text-small;
    }
  }
</style>

The reference is needed so Tailwind classes like text-small are recognized when working with @apply. Still, you can also use layers without that:

html
<style>
  @layer components {
    .element {
      font-size: 12px;
    }
  }
</style>

Please refer to https://tailwindcss.com/docs/adding-custom-styles#using-custom-css for more information on layers and how to write custom CSS with Tailwind.

OcCard

OcCard is now a dedicated component instead of a class.

ts
<div class="oc-card">
<oc-card>
  <div class="oc-card-header">
    <template #header>
    <h2>Card title</h2>
  </div>
  </template>
  <div class="oc-card-body">
    <p>Some body content</p>
  </div>
  <div class="oc-card-footer">
  <template #footer>
    <p>Some footer</p>
  </div>
  </template>
</div>
</oc-card>

Please refer to the OcCard docs for more details on how to use this component.

OcGrid

The OcGrid component has been removed. Please use the Tailwind grid layout instead.

Mixins

The following mixins have been removed:

  • oc-form-check-size
  • oc-icon-size
  • oc-spinner-size

Media queries (breakpoints)

The custom breakpoint variables have been removed:

  • $oc-breakpoint-xsmall-max
  • $oc-breakpoint-small-default
  • $oc-breakpoint-small-max
  • $oc-breakpoint-medium-default
  • $oc-breakpoint-medium-max
  • $oc-breakpoint-large-default
  • $oc-breakpoint-large-max
  • $oc-breakpoint-xlarge

Please use the corresponding Tailwind utilities instead. The old breakpoints have been mapped to those.

ts
<div class="element" />
<div class="hidden sm:block" />

<style> 
  .element { 
    display: block; 
  } 
  @media (max-width: $oc-breakpoint-small-default) { 
    .element { 
      display: none; 
    } 
  } 
</style>

Theming options

The theming options for breakpoints, spacing, fontSizes and sizes have been removed. They just added unnecessary complexity and are not needed with Tailwind.