6.0.57 • Published 20 days ago

dom-flair v6.0.57

Weekly downloads
-
License
-
Repository
github
Last release
20 days ago

DOM Flair

The goal of this project is to solve any or most html layout issues in intuitive ways via the attribute flair without having to think much about CSS. For example <div flair="col grow"></div>. That's it.

It could also help with trivial CSS, For example <div flair="text-capitalize"></div> to capitalize the div contents.

Installation & Usage

ES module

npm install dom-flair

Import it where you gonna use is

import 'dom-flair'

Note: The element you mount to, should be display:flex;flex:1; for the attribute to work.

Babel Plugin

The style-sheet has around 800~ lines, you may want to include only what you use. There's a babel plugin that will look for the attribute in jsx elements and create a style-sheet with the minimal output to the desired location. Then import it as you wish.

{
	"babel": {
		"plugins": [
			[
				"dom-flair/babel",
				{
					// where the stylesheet should be created
					"path": "client/dist/flair.css",
					// to include a style reset
					"reset": true
				}
			]
		]
	}
}

Examples

The "Holy Grail Layout":

Sticky footer

<div flair="col grow">
	<div>header</div>
	<div flair="grow">content</div>
	<div>footer</div>
</div>

Elaborate Example:

Has two sidebars, a toolbar, a footer, and grows in the middle content:

<div flair="grow">
	<div flair="col grow horizontal">left sidebar</div>
	<div flair="col grow">
		<div flair="row right">toolbar</div>
		<div flair="row grow center">content</div>
		<div flair="row left">footer</div>
	</div>
	<div flair="col grow center">right sidebar</div>
</div>

Values supported

Direction

Sets the direction of the children.

valuedescription
rowchildren will display as a row
col, columnchildren will display as a column
wrapwraps the children as in flex-wrap
no-wrapdisables wrapping as in flex-wrap

Size

valuedescription
growgrow self as much as it can without growing the children
full-widthsets the width to 100%
min-widthsets the min-width to 100%
max-widthsets the max-width to 100%
full-heightsets the height to 100%
min-heightsets the min-height to 100%
max-heightsets the max-height to 100%

Children Alignment

Alignment of the children, NOT the alignment of the content of these children. Example: You can display a div aligned to the left, but the text on it aligned to the right. Well, in here we only control the div itself and not the div content.

valuedescription
leftaligns to left, sets left to 0
topaligns to top, sets top to 0
rightaligns to right, sets right to 0
bottomaligns to bottom, sets botttom to 0
horizontalaligns to the center horizontally
verticalaligns to the center vertically
centeraligns to center, both horizontally and vertically

Space Between Children Elements

valuedescription
space-around-horizontalspace-around
space-around-verticalspace-around
space-aroundspace-around
space-between-horizontalspace-between
space-between-verticalspace-between
space-betweenspace-between
space-evenly-horizontalspace-evenly
space-evenly-verticalspace-evenly
space-evenlyspace-evenly

Bugs

  • space-around, space-between and space-evenly use align-content: initial; to workaround "Can't scroll to top of flex item that is overflowing container"
  • safe center values looks like it does not work correctly
  • space-* seem to have problems with columns maybe

Text

valuedescription
text-centersets text-align to center
text-leftsets text-align to left
text-rightsets text-align to right
text-boldbold font
text-cropcrops the text
text-multilinesets line-height:1.4;
text-regularno bold font
text-smallfont size small
text-underlineunderline
text-no-underlinedo not underline
text-capitalizecapitalize
text-uppercaseuppercase
text-no-wrapnowrap the text if it overflows
text-wrapwrap the text if it overflows
text-preuse pre-wrap

Bugs

  • text-crop ellipsis will only be shown if the container in not display:flex (aka not row/col/grow), if you want to show ellipsis in a flex container then wrap it like <div flair="row"><div flair="text-crop">The..</div></div>

Scroll

valuedescription
scrollscrolls both vertically and horizontally when overflows
scroll-xscrolls horizontally when overflows
scroll-yscrolls vertically when overflows
scroll-thinto set the size of the scrollbar to thin
no-scrollto set the size of the scrollbar to 0px and display none
scroll-colorsets the color for scroll <div flair="scroll-color" style="--scroll-color:black;--scroll-background:black "></div>

Bugs

  • scroll-color and scroll-background must both be provided for this properties to work

Selection

valuedescription
selection-noneprevent text selection
selection-allselects all text on focus
selection-textallows text selection
selection-colorselection text color <div flair="selection-color" style="--selection-color:black"></div>
selection-backgroundselection background color <div flair="selection-background" style="--selection-background:black"></div>
draggable='false'sets touch-action: none; and -webkit-user-drag: none;
draggable='true'sets touch-action: initial; and -webkit-user-drag: initial;

Cursor

valuedescription
cursor-handcursor pointer
cursor-ignoreignore events
cursor-no-ignoredont ignore events

Display

valuedescription
absoluteposition absolute
relativeposition relative
fixedposition fixed
fullfull width and height with overflow hidden
full-windowfull width and height with overflow hidden and top and left 0
blockdisplay block
inlinedisplay inline
inline-blockdisplay inline-block
inline-flexdisplay inline-flex
hiddendisplay none
collapsesets the visibility to collapsed
layerforces a layer using transform:translateZ(0);
overflowoverflow hidden
visibleoverflow visible
border-boxbox-sizing property
content-boxbox-sizing property
no-emptyhides the element if empty
circleset border-radius to 100%
controls-nonehide video/audio controls
absolute-centerposition absolute - top, left: 50% - translate top left -50%

Shadows

valuedescription
text-shadow<div flair="text-shadow" style="--text-shadow-color:black"></div> can also be used on svg which use a drop-shadow instead trying to match the text shadow.
box-shadowsimilar to text-shadow but for boxes. <div flair="text-shadow" style="--box-shadow-color:black"></div>

Backgrounds

valuedescription
chess-backgroundapplies a checkered background

Features

  • easy to think about layouts
  • some handy default attributes
  • deduplicates css
  • is efficient

Authors

6.0.57

20 days ago

6.0.56

4 months ago

6.0.55

4 months ago

6.0.54

5 months ago

6.0.53

5 months ago

6.0.52

5 months ago

6.0.51

5 months ago

6.0.49

6 months ago

6.0.48

6 months ago

6.0.46

7 months ago

6.0.45

9 months ago

6.0.41

12 months ago

6.0.40

12 months ago

6.0.44

12 months ago

6.0.43

12 months ago

6.0.42

12 months ago

6.0.39

12 months ago