Skip to content

tailwindParser

@threlte/flex ships with a default parser for Tailwind-like classes on <Flex> and <Box> components. If you are familiar with Tailwind, you will feel right at home.

<Flex
width={300}
height={300}
classParser={tailwindParser}
class="flex-col items-center justify-center gap-10 p-10"
>
<Box class="w-100 h-full shrink-0">
{#snippet children({ width, height })}
<Plane
{width}
{height}
color="yellow"
depth={1}
/>
{/snippet}
</Box>
<Box class="flex-1">
{#snippet children({ width })}
<Plane
color="blue"
{width}
height={44}
depth={1}
/>
{/snippet}
</Box>
</Flex>

Add the classParser prop to your <Flex> or <Box> component and pass in the tailwindParser function.

<script>
import { Flex, Box, Plane, tailwindParser } from '@threlte/flex'
</script>
<Flex
width={300}
height={300}
classParser={tailwindParser}
class="flex-col items-center justify-center gap-10 p-10"
>
<Box class="h-100 w-100">
{#snippet children({ width, height })}
<!-- … -->
{/snippet}
</Box>
</Flex>

The syntax is very similar to Tailwind, with a few differences:

  • If a value is a number, it is interpreted as a unit in Three.js. For example, gap-10 will set the gap to 10 Three.js units.
  • As opposed to Tailwind, you are not limited to the default set of values. You can use any value: gap-17.5 will set the gap to 17.5 Three.js units. p-56% will set the padding to 56% of the parent’s width. Do not wrap the value in brackets as you would do with custom values in Tailwind CSS.

The following props are supported by the Tailwind parser:

ClassCSS Properties
flex-rowflex-direction: row
flex-colflex-direction: column
flex-row-reverseflex-direction: row-reverse
flex-col-reverseflex-direction: column-reverse
ClassCSS Properties
flex-wrapflex-wrap: wrap
flex-wrap-reverseflex-wrap: wrap-reverse
flex-nowrapflex-wrap: nowrap
ClassCSS Properties
justify-startjustify-content: flex-start
justify-endjustify-content: flex-end
justify-centerjustify-content: center
justify-betweenjustify-content: space-between
justify-aroundjustify-content: space-around
justify-evenlyjustify-content: space-evenly
ClassCSS Properties
items-startalign-items: flex-start
items-endalign-items: flex-end
items-centeralign-items: center
items-baselinealign-items: baseline
items-stretchalign-items: stretch
ClassCSS Properties
content-normal align-content: normal
content-startalign-content: flex-start
content-endalign-content: flex-end
content-centeralign-content: center
content-betweenalign-content: space-between
content-aroundalign-content: space-around
content-stretchalign-content: stretch
content-baselinealign-content: baseline

value is a number (e.g. 10)

ClassCSS PropertiesExamples
gap-{value}gapgap-10
gap-x-{value}column-gapgap-x-10
gap-y-{value}row-gapgap-y-10

value is a number (e.g. 1)

ClassCSS PropertiesExamples
grow-{value}flex-growgrow-1, grow-0

value is a number (e.g. 1)

ClassCSS PropertiesExamples
shrink-{value}flex-shrinkshrink-1, shrink-0

value can be auto, full, a percentage (e.g. 55%) or a number (e.g. 10).

ClassCSS PropertiesExamples
basis-{value}flex-basisbasis-10, basis-full, basis-55%, basis-auto

value is a number (e.g. 1)

ClassCSS PropertiesExamples
flex-{value}flexflex-1, flex-0.5
ClassCSS Properties
self-autoalign-self: auto
self-startalign-self: flex-start
self-endalign-self: flex-end
self-centeralign-self: center
self-stretchalign-self: stretch
self-baselinealign-self: baseline

value can be full, a percentage (e.g. 55%) or a number (e.g. 10).

ClassCSS PropertiesExamples
p-{value}paddingp-10, p-full, p-55%
pt-{value}padding-toppt-10, pt-full, pt-55%
pr-{value}padding-rightpr-10, pr-full, pr-55%
pb-{value}padding-bottompb-10, pb-full, pb-55%
pl-{value}padding-leftpl-10, pl-full, pl-55%
px-{value}padding-left
padding-right
px-10, px-full, px-55%
py-{value}padding-top
padding-bottom
py-10, py-full, py-55%

value can be full, a percentage (e.g. 55%) or a number (e.g. 10).

ClassCSS PropertiesExamples
m-{value}marginm-10, m-full, m-55%
mt-{value}margin-topmt-10, mt-full, mt-55%
mr-{value}margin-rightmr-10, mr-full, mr-55%
mb-{value}margin-bottommb-10, mb-full, mb-55%
ml-{value}margin-leftml-10, ml-full, ml-55%
mx-{value}margin-left
margin-right
mx-10, mx-full, mx-55%
my-{value}margin-top
margin-bottom
my-10, my-full, my-55%

value can be auto, full, a percentage (e.g. 55%) or a number (e.g. 10).

ClassCSS PropertiesExamples
w-{value}widthw-10, w-full, w-55%, w-auto

value can be auto, full, a percentage (e.g. 55%) or a number (e.g. 10).

ClassCSS PropertiesExamples
h-{value}heighth-10, h-full, h-55%, h-auto

value can be a percentage (e.g. 55%) or a number (e.g. 10).

ClassCSS PropertiesExamples
top-{value}toptop-10, top-55%
right-{value}rightright-10, right-55%
bottom-{value}bottombottom-10, bottom-55%
left-{value}leftleft-10, left-55%

value can be square, portrait, landscape or an arbitrary ratio (e.g. 32/9).

ClassCSS PropertiesExamples
aspect-square aspect-ratio: 1 / 1
aspect-portraitaspect-ratio: 9 / 16
aspect-landscapeaspect-ratio: 16 / 9
aspect-{value}aspect-ratio: {value}aspect-32/9, aspect-2/1