5.0.38 • Published 12 months ago

@titodp/styled v5.0.38

Weekly downloads
-
License
-
Repository
github
Last release
12 months ago

Styled

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

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

Installation & Usage

ES module

npm install @titodp/styled

Import it where you gonna use is

import '@titodp/styled'

Note: The element you mount to, should be display:flex;flex:1; for the attributes 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 at the attributes of jsx elements and create a style-sheet with the output to the desired location.

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

Examples

The "Holy Grail Layout":

Sticky footer

<div col grow>
	<div>header</div>
	<div grow>content</div>
	<div>footer</div>
</div>

Elaborate Example:

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

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

Attributes supported

Direction

Sets the direction of the children.

attributedescription
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

attributedescription
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.

attributedescription
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

attributedescription
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

attributedescription
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 row><div text-crop>The..</div></div>

Scroll

attributedescription
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 the bar <div scroll-color style="--scroll-color:black"></div>
scroll-backgroundsets the color for the background <div scroll-background style="--scroll-background:black"></div>

Bugs

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

Selection

attributedescription
selection-noneprevent text selection
selection-allselects all text on focus
selection-textallows text selection
selection-colorselection text color <div selection-color style="--selection-color:black"></div>
selection-backgroundselection background color <div 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

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

Display

attributedescription
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

Shadows

attributedescription
text-shadow<div 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 text-shadow style="--box-shadow-color:black"></div>

Backgrounds

attributedescription
chess-backgroundapplies a checkered background

Features

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

Authors

URL: https://github.com/titoBouzout/styled

5.0.36

12 months ago

5.0.37

12 months ago

5.0.38

12 months ago

4.0.32

1 year ago

4.0.34

12 months ago

4.0.35

12 months ago

3.0.31

2 years ago

3.0.30

2 years ago

3.0.29

2 years ago

3.0.28

2 years ago

3.0.27

2 years ago

3.0.26

2 years ago

3.0.25

2 years ago

3.0.24

2 years ago

3.0.23

2 years ago

3.0.22

2 years ago