@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.
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 })}
{# snippet children ({ width })}
Add the classParser prop to your <Flex> or <Box> component and pass in the tailwindParser function.
import { Flex, Box, Plane, tailwindParser } from ' @threlte/flex '
classParser = { tailwindParser }
class = " flex-col items-center justify-center gap-10 p-10 "
< Box class = " h-100 w-100 " >
{# snippet children ({ width, height })}
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:
Class CSS Properties flex-rowflex-direction: rowflex-colflex-direction: columnflex-row-reverseflex-direction: row-reverseflex-col-reverseflex-direction: column-reverse
Class CSS Properties flex-wrapflex-wrap: wrapflex-wrap-reverseflex-wrap: wrap-reverseflex-nowrapflex-wrap: nowrap
Class CSS Properties justify-startjustify-content: flex-startjustify-endjustify-content: flex-endjustify-centerjustify-content: centerjustify-betweenjustify-content: space-betweenjustify-aroundjustify-content: space-aroundjustify-evenlyjustify-content: space-evenly
Class CSS Properties items-startalign-items: flex-startitems-endalign-items: flex-enditems-centeralign-items: centeritems-baselinealign-items: baselineitems-stretchalign-items: stretch
Class CSS Properties content-normal align-content: normalcontent-startalign-content: flex-startcontent-endalign-content: flex-endcontent-centeralign-content: centercontent-betweenalign-content: space-betweencontent-aroundalign-content: space-aroundcontent-stretchalign-content: stretchcontent-baselinealign-content: baseline
value is a number (e.g. 10)
Class CSS Properties Examples gap-{value}gapgap-10gap-x-{value}column-gapgap-x-10gap-y-{value}row-gapgap-y-10
value is a number (e.g. 1)
Class CSS Properties Examples grow-{value}flex-growgrow-1, grow-0
value is a number (e.g. 1)
Class CSS Properties Examples shrink-{value}flex-shrinkshrink-1, shrink-0
value can be auto, full, a percentage (e.g. 55%) or a number (e.g. 10).
Class CSS Properties Examples basis-{value}flex-basisbasis-10, basis-full, basis-55%, basis-auto
value is a number (e.g. 1)
Class CSS Properties Examples flex-{value}flexflex-1, flex-0.5
Class CSS Properties self-autoalign-self: autoself-startalign-self: flex-startself-endalign-self: flex-endself-centeralign-self: centerself-stretchalign-self: stretchself-baselinealign-self: baseline
value can be full, a percentage (e.g. 55%) or a number (e.g. 10).
Class CSS Properties Examples 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-leftpadding-rightpx-10, px-full, px-55%py-{value}padding-toppadding-bottompy-10, py-full, py-55%
value can be full, a percentage (e.g. 55%) or a number (e.g. 10).
Class CSS Properties Examples 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-leftmargin-rightmx-10, mx-full, mx-55%my-{value}margin-topmargin-bottommy-10, my-full, my-55%
value can be auto, full, a percentage (e.g. 55%) or a number (e.g. 10).
Class CSS Properties Examples 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).
Class CSS Properties Examples h-{value}heighth-10, h-full, h-55%, h-auto
value can be a percentage (e.g. 55%) or a number (e.g. 10).
Class CSS Properties Examples 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).
Class CSS Properties Examples aspect-square aspect-ratio: 1 / 1aspect-portraitaspect-ratio: 9 / 16aspect-landscapeaspect-ratio: 16 / 9aspect-{value}aspect-ratio: {value}aspect-32/9, aspect-2/1