Skip to content

Commit 523fd20

Browse files
author
Richard Feldman
committed
Move some things around; revise docs.
1 parent 5047417 commit 523fd20

File tree

8 files changed

+125
-68
lines changed

8 files changed

+125
-68
lines changed

README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,18 @@ main =
104104

105105
See [the `Css` module documentation](http://package.elm-lang.org/packages/rtfeldman/elm-css/latest/Css) for an explanation of how this code works.
106106

107-
`elm-css` draws inspiration from the excellent [Sass](http://sass-lang.com/), [Stylus](http://stylus-lang.com/), [CSS Modules](http://glenmaddern.com/articles/css-modules), and [styled-components](https://www.styled-components.com). It includes popular features like:
107+
`elm-css` draws inspiration from the excellent [Sass](http://sass-lang.com/), [Stylus](http://stylus-lang.com/), [CSS Modules](http://glenmaddern.com/articles/css-modules), and [styled-components](https://www.styled-components.com) libraries. It includes features like:
108108

109-
- [Mixins](http://package.elm-lang.org/packages/rtfeldman/elm-css/latest/Css#mixin)
110-
- [namespaces](http://package.elm-lang.org/packages/rtfeldman/elm-css/latest/Css-Namespace#namespace)
111-
- [nested media queries](https://davidwalsh.name/write-media-queries-sass) (and nested selectors in general, like how [Sass](http://sass-lang.com/) does them)
109+
- [locally scoped CSS](https://medium.com/seek-blog/the-end-of-global-css-90d2a4a06284)
110+
- [mixins](http://package.elm-lang.org/packages/rtfeldman/elm-css/latest/Css#batch)
111+
- [nested media queries](https://davidwalsh.name/write-media-queries-sass) (as well as pseudo-classes like `:hover` and pseudo-elements like `::after`)
112112

113113
### Examples
114114

115-
There are a few examples to check out!
116-
117-
- [json-to-elm](https://github.com/eeue56/json-to-elm) which can see be seen live [here](https://noredink.github.io/json-to-elm)
118-
- the [examples](https://github.com/rtfeldman/elm-css/tree/master/examples) folder, which contains a working project with a README
119-
- the example above
120-
115+
- A [reusable datepicker](https://github.com/abadi199/datetimepicker) built by Abadi Kurniawan
116+
- The [website](https://noredink.github.io/json-to-elm) for [json-to-elm](https://github.com/eeue56/json-to-elm)
117+
- This project's [examples](https://github.com/rtfeldman/elm-css/tree/master/examples) folder
121118

122119
## Related Projects
123120

124-
* [Elm CSS Normalize](https://github.com/scottcorgan/elm-css-normalize)
121+
- [Elm CSS Normalize](https://github.com/scottcorgan/elm-css-normalize)

src/Css.elm

Lines changed: 74 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ module Css
109109
, any
110110
, arabicIndic
111111
, armenian
112-
, asPairs
112+
, asPairsDEPRECATED
113113
, auto
114114
, backgroundAttachment
115115
, backgroundBlendMode
@@ -839,14 +839,14 @@ a [`Html.Styled`](Html-Styled) value which wraps a normal `Html` value and adds
839839
styling information. Later, when you call [`toUnstyled`](Html-Styled#toUnstyled)
840840
to convert this value to a normal `Html` value, it adds two elements to the DOM:
841841
842-
<button class="df8ab1">Reset<button>
842+
<button class="_df8ab1">Reset<button>
843843
844844
<style>
845-
.df8ab1 {
846-
border-raidus: 10px;
845+
._df8ab1 {
846+
border-radius: 10px;
847847
}
848848
849-
.df8ab1:hover {
849+
._df8ab1:hover {
850850
text-decoration: underline;
851851
}
852852
</style>
@@ -857,37 +857,69 @@ To sum up what's happening here:
857857
2. That classname gets added to the element receiving the attiibute, and the style information gets stored in the `Html.Styled` value which wraps that element.
858858
3. Calling `toUnstyled` converts this `Html.Styled` value to a normal `Html` value which represents both the requested element as well as a `<style>` element
859859
860-
This is how the elm-css `css` attribute is able to support things like
860+
This is how the `css` attribute is able to support things like `hover` and media
861+
queries.
861862
863+
`toUnstyled` avoids generating excess `<style>` elements and CSS declarations
864+
by building up a dictionary of styles you've passed to `css`. It will use
865+
that dictionary to add a single `<style>` to the DOM with the appropriate
866+
classname declarations.
862867
863-
#### Missing CSS properties
864868
865-
`elm-css` is still in development. Not all CSS properties have been added yet.
866-
If you run into this problem, `elm-css` includes the `property` function. It takes
867-
two `Strings`; the property key, and its value.
869+
#### Style Reuse
868870
869-
**e.g.**
871+
The easiest way to reuse styles (like [mixins](http://sass-lang.com/guide#topic-6)
872+
in other CSS systems) is through [`Style`](http://package.elm-lang.org/packages/rtfeldman/elm-css/latest/Css#Style)
873+
values.
870874
871-
We want `z-index`, but suppose `elm-css` did not implement it. We would define it ourselves:
875+
greenBorder : Style
876+
greenBorder =
877+
borderColor green
872878
873-
import Css exposing (..)
879+
bigBold : Style
880+
bigBold =
881+
Css.batch [ fontWeight bold, fontSize (px 48) ]
874882
875-
zIndex : Int -> Mixin
876-
zIndex i =
877-
property "z-index" <| toString i
883+
view : Model -> Html Msg
884+
view model =
885+
button [ css [ bigBold, greenBorder ] ] [ text "Ok" ]
878886
879-
Now `zIndex 9999` is available to use inside our `Stylesheet`.
887+
Another way to reuse styles is to compile them to attributes and then to mix
888+
and match those. This is less flexible than mixing and matching `Style` values,
889+
but it has a performance benefit: classname hashes are calculated when you call
890+
the `css` function, so you can avoid redoing that work by calling it at the top level.
880891
892+
greenBorder : Attribute msg
893+
greenBorder =
894+
css [ borderColor green ]
881895
882-
# Misc
896+
bigBold : Attribute msg
897+
bigBold =
898+
css [ fontWeight bold, fontSize (px 48) ]
883899
884-
@docs Compatible, asPairs, absolute, all, allPetiteCaps, allSmallCaps, auto, baseline, block, bold, bolder, border, border2, border3, borderBlockEnd, borderBlockEnd2, borderBlockEnd3, borderBlockEndColor, borderBlockEndStyle, borderBlockStart, borderBlockStart2, borderBlockStart3, borderBlockStartColor, borderBlockStartStyle, borderBottom, borderBottom2, borderBottom3, borderBottomColor, borderBottomLeftRadius, borderBottomLeftRadius2, borderBottomRightRadius, borderBottomRightRadius2, borderBottomStyle, borderWidth, borderWidth2, borderWidth3, borderWidth4, borderBottomWidth, borderBox, borderColor, borderColor2, borderColor3, borderColor4, borderImageOutset, borderImageOutset2, borderImageOutset3, borderImageOutset4, borderImageWidth, borderImageWidth2, borderImageWidth3, borderImageWidth4, borderInlineEnd, borderInlineEnd2, borderInlineEnd3, borderInlineEndColor, borderInlineEndStyle, borderInlineEndWidth, borderInlineStart, borderInlineStart2, borderInlineStart3, borderInlineStartColor, borderInlineStartStyle, borderLeft, borderLeft2, borderLeft3, borderLeftColor, borderLeftStyle, borderLeftWidth, borderRadius, borderRadius2, borderRadius3, borderRadius4, borderRight, borderRight2, borderRight3, borderRightColor, borderRightStyle, borderRightWidth, borderStyle, borderCollapse, borderTop, borderTop2, borderTop3, borderTopColor, borderTopLeftRadius, borderTopLeftRadius2, borderTopRightRadius, borderTopRightRadius2, borderTopStyle, borderTopWidth, bottom, column, columnReverse, commonLigatures, content, contentBox, contextual, cursive, dashed, diagonalFractions, discretionaryLigatures, dotted, double, fantasy, fillBox, fixed, flat, displayFlex, flexEnd, flexStart, groove, hex, hidden, historicalLigatures, hsl, hsla, important, inherit, initial, inline, inlineBlock, inlineFlex, table, inlineTable, tableCell, tableRow, tableColumn, tableCaption, tableRowGroup, tableColumnGroup, tableHeaderGroup, tableFooterGroup, inlineListItem, inset, italic, large, larger, lighter, liningNums, listItem, manipulation, matrix, matrix3d, middle, monospace, noCommonLigatures, noContextual, noDiscretionaryLigatures, noHistoricalLigatures, noWrap, none, normal, oblique, oldstyleNums, ordinal, outset, panX, panLeft, panRight, panY, panUp, panDown, perspective, petiteCaps, pinchZoom, position, float, preserve3d, proportionalNums, relative, rgb, rgba, ridge, rotate, rotate3d, rotateX, rotateY, rotateZ, row, rowReverse, sansSerif, scale, scale2, scale3d, scaleX, scaleY, scroll, serif, skew, skew2, skewX, skewY, slashedZero, small, smallCaps, smaller, solid, stackedFractions, static, sticky, stretch, sub, super, tabularNums, textBottom, textTop, titlingCaps, top, translate, translate2, translate3d, translateX, translateY, translateZ, transparent, unicase, unset, viewBox, visible, wavy, wrap, wrapReverse, xLarge, xSmall, xxLarge, xxSmall, backgroundRepeat, backgroundRepeat2, repeatX, repeatY, repeat, space, round, noRepeat, backgroundAttachment, local, backgroundBlendMode, multiply, overlay, darken, lighten, colorDodge, colorBurn, hardLight, softLight, difference, exclusion, hue, saturation, luminosity, screenBlendMode, backgroundClip, paddingBox, backgroundImage, url, backgroundPosition, backgroundPosition2, backgroundOrigin, backgroundSize, backgroundSize2, cover, contain, both, horizontal, vertical, breakWord, spaceAround, spaceBetween, separate, collapse
885-
@docs listStyleType, disc, circle, square, decimal, decimalLeadingZero, lowerRoman, upperRoman, lowerGreek, lowerAlpha, lowerLatin, upperAlpha, upperLatin, arabicIndic, armenian, bengali, cjkEarthlyBranch, cjkHeavenlyStem, devanagari, georgian, gujarati, gurmukhi, kannada, khmer, lao, malayalam, myanmar, oriya, telugu, thai
886-
@docs listStylePosition, inside, outside
887-
@docs listStyle, listStyle2, listStyle3
888-
@docs linearGradient, linearGradient2, stop, stop2, toBottom, toBottomLeft, toBottomRight, toLeft, toRight, toTop, toTopLeft, toTopRight
900+
view : Model -> Html Msg
901+
view model =
902+
button [ bigBold, greenBorder ] [ text "Ok" ]
903+
904+
The `greenBorder` and `bigBold` attributes above will have their classname hashes
905+
calculated right when `css` is called, and never again. The button will have a
906+
green border, a bold font weight, and a font size of 48px.
907+
908+
You can also use [`Html.Styled.Lazy`](http://package.elm-lang.org/packages/rtfeldman/elm-css/latest/Css#property)
909+
to avoid recomputing both hashes and `Html` nodes.
889910
890-
@docs AlignItems, All, Angle, AngleOrDirection, BackgroundAttachment, BackgroundBlendMode, BackgroundClip, BackgroundImage, BackgroundOrigin, BackgroundRepeat, BackgroundRepeatShorthand, BasicProperty, BorderCollapse, BorderStyle, BoxSizing, Calc, CalcExpression, Cursor, Directionality, Display, ExplicitLength, FeatureTagValue, FlexBasis, FlexDirection, FlexDirectionOrWrap, FlexWrap, FontFamily, FontStyle, FontStyleOrFeatureTagValue, FontVariant, FontVariantCaps, FontVariantLigatures, FontVariantNumeric, FontWeight, ImportType, IncompatibleUnits, JustifyContent, LengthOrAuto, LengthOrAutoOrCoverOrContain, LengthOrMinMaxDimension, LengthOrNone, LengthOrNoneOrMinMaxDimension, LengthOrNumber, LengthOrNumberOrAutoOrNoneOrContent, ListStyle, ListStylePosition, ListStyleType, MinMaxDimension, NonMixable, None, Number, Outline, Overflow, Position, Resize, TextDecorationLine, TextDecorationStyle, TextIndent, TextOrientation, TextOverflow, TextRendering, TextTransform, TouchAction, Transform, TransformBox, TransformStyle, Value, VerticalAlign, WhiteSpace, Wrap, pre, preLine, preWrap
911+
912+
#### Unsupported Properties
913+
914+
The CSS spec is, ahem, not small. `elm-css` covers a lot of it, but not all of
915+
it. Some things are considered too experimental to support, usually because they
916+
do not have enough browser support. Others haven't been added yet because, well,
917+
we haven't gotten around to adding them!
918+
919+
If you need something that `elm-css` does not support right now, the
920+
[`Css.property`](http://package.elm-lang.org/packages/rtfeldman/elm-css/latest/Css#property)
921+
and [`Css.Foreign.selector`](http://package.elm-lang.org/packages/rtfeldman/elm-css/latest/Css-Foreign#selector)
922+
functions let you define custom properties and selectors, respectively.
891923
892924
893925
# Style
@@ -953,6 +985,17 @@ Now `zIndex 9999` is available to use inside our `Stylesheet`.
953985
@docs qt
954986
955987
988+
# Misc
989+
990+
@docs Compatible, asPairsDEPRECATED, absolute, all, allPetiteCaps, allSmallCaps, auto, baseline, block, bold, bolder, border, border2, border3, borderBlockEnd, borderBlockEnd2, borderBlockEnd3, borderBlockEndColor, borderBlockEndStyle, borderBlockStart, borderBlockStart2, borderBlockStart3, borderBlockStartColor, borderBlockStartStyle, borderBottom, borderBottom2, borderBottom3, borderBottomColor, borderBottomLeftRadius, borderBottomLeftRadius2, borderBottomRightRadius, borderBottomRightRadius2, borderBottomStyle, borderWidth, borderWidth2, borderWidth3, borderWidth4, borderBottomWidth, borderBox, borderColor, borderColor2, borderColor3, borderColor4, borderImageOutset, borderImageOutset2, borderImageOutset3, borderImageOutset4, borderImageWidth, borderImageWidth2, borderImageWidth3, borderImageWidth4, borderInlineEnd, borderInlineEnd2, borderInlineEnd3, borderInlineEndColor, borderInlineEndStyle, borderInlineEndWidth, borderInlineStart, borderInlineStart2, borderInlineStart3, borderInlineStartColor, borderInlineStartStyle, borderLeft, borderLeft2, borderLeft3, borderLeftColor, borderLeftStyle, borderLeftWidth, borderRadius, borderRadius2, borderRadius3, borderRadius4, borderRight, borderRight2, borderRight3, borderRightColor, borderRightStyle, borderRightWidth, borderStyle, borderCollapse, borderTop, borderTop2, borderTop3, borderTopColor, borderTopLeftRadius, borderTopLeftRadius2, borderTopRightRadius, borderTopRightRadius2, borderTopStyle, borderTopWidth, bottom, column, columnReverse, commonLigatures, content, contentBox, contextual, cursive, dashed, diagonalFractions, discretionaryLigatures, dotted, double, fantasy, fillBox, fixed, flat, displayFlex, flexEnd, flexStart, groove, hex, hidden, historicalLigatures, hsl, hsla, important, inherit, initial, inline, inlineBlock, inlineFlex, table, inlineTable, tableCell, tableRow, tableColumn, tableCaption, tableRowGroup, tableColumnGroup, tableHeaderGroup, tableFooterGroup, inlineListItem, inset, italic, large, larger, lighter, liningNums, listItem, manipulation, matrix, matrix3d, middle, monospace, noCommonLigatures, noContextual, noDiscretionaryLigatures, noHistoricalLigatures, noWrap, none, normal, oblique, oldstyleNums, ordinal, outset, panX, panLeft, panRight, panY, panUp, panDown, perspective, petiteCaps, pinchZoom, position, float, preserve3d, proportionalNums, relative, rgb, rgba, ridge, rotate, rotate3d, rotateX, rotateY, rotateZ, row, rowReverse, sansSerif, scale, scale2, scale3d, scaleX, scaleY, scroll, serif, skew, skew2, skewX, skewY, slashedZero, small, smallCaps, smaller, solid, stackedFractions, static, sticky, stretch, sub, super, tabularNums, textBottom, textTop, titlingCaps, top, translate, translate2, translate3d, translateX, translateY, translateZ, transparent, unicase, unset, viewBox, visible, wavy, wrap, wrapReverse, xLarge, xSmall, xxLarge, xxSmall, backgroundRepeat, backgroundRepeat2, repeatX, repeatY, repeat, space, round, noRepeat, backgroundAttachment, local, backgroundBlendMode, multiply, overlay, darken, lighten, colorDodge, colorBurn, hardLight, softLight, difference, exclusion, hue, saturation, luminosity, screenBlendMode, backgroundClip, paddingBox, backgroundImage, url, backgroundPosition, backgroundPosition2, backgroundOrigin, backgroundSize, backgroundSize2, cover, contain, both, horizontal, vertical, breakWord, spaceAround, spaceBetween, separate, collapse
991+
@docs listStyleType, disc, circle, square, decimal, decimalLeadingZero, lowerRoman, upperRoman, lowerGreek, lowerAlpha, lowerLatin, upperAlpha, upperLatin, arabicIndic, armenian, bengali, cjkEarthlyBranch, cjkHeavenlyStem, devanagari, georgian, gujarati, gurmukhi, kannada, khmer, lao, malayalam, myanmar, oriya, telugu, thai
992+
@docs listStylePosition, inside, outside
993+
@docs listStyle, listStyle2, listStyle3
994+
@docs linearGradient, linearGradient2, stop, stop2, toBottom, toBottomLeft, toBottomRight, toLeft, toRight, toTop, toTopLeft, toTopRight
995+
996+
@docs AlignItems, All, Angle, AngleOrDirection, BackgroundAttachment, BackgroundBlendMode, BackgroundClip, BackgroundImage, BackgroundOrigin, BackgroundRepeat, BackgroundRepeatShorthand, BasicProperty, BorderCollapse, BorderStyle, BoxSizing, Calc, CalcExpression, Cursor, Directionality, Display, ExplicitLength, FeatureTagValue, FlexBasis, FlexDirection, FlexDirectionOrWrap, FlexWrap, FontFamily, FontStyle, FontStyleOrFeatureTagValue, FontVariant, FontVariantCaps, FontVariantLigatures, FontVariantNumeric, FontWeight, ImportType, IncompatibleUnits, JustifyContent, LengthOrAuto, LengthOrAutoOrCoverOrContain, LengthOrMinMaxDimension, LengthOrNone, LengthOrNoneOrMinMaxDimension, LengthOrNumber, LengthOrNumberOrAutoOrNoneOrContent, ListStyle, ListStylePosition, ListStyleType, MinMaxDimension, NonMixable, None, Number, Outline, Overflow, Position, Resize, TextDecorationLine, TextDecorationStyle, TextIndent, TextOrientation, TextOverflow, TextRendering, TextTransform, TouchAction, Transform, TransformBox, TransformStyle, Value, VerticalAlign, WhiteSpace, Wrap, pre, preLine, preWrap
997+
998+
956999
# Types
9571000
9581001
@docs FontSize, ColorValue, ColorStop, IntOrAuto
@@ -8307,18 +8350,20 @@ stringsToValue list =
83078350
{ value = String.join ", " (List.map (\s -> s) list) }
83088351

83098352

8310-
{-| Take a list of styles and return a list of key-value pairs that
8353+
{-| DEPRECATED in favor of [`Html.Styled.Attributes.css`](Html-Styled-Attributes#css). This function will be removed in the next major release of elm-css.
8354+
8355+
Take a list of styles and return a list of key-value pairs that
83118356
can then be passed to a `style` attribute.
83128357
8313-
styled = asPairs >> Html.Attributes.style
8358+
styles = asPairs >> Html.Attributes.style
83148359
83158360
button
8316-
[ styled [ position absolute, left (px 5) ] ]
8361+
[ styles [ position absolute, left (px 5) ] ]
83178362
[ text "Whee!" ]
83188363
83198364
-}
8320-
asPairs : List Style -> List ( String, String )
8321-
asPairs =
8365+
asPairsDEPRECATED : List Style -> List ( String, String )
8366+
asPairsDEPRECATED =
83228367
Preprocess.toPropertyPairs
83238368

83248369

src/Css/Foreign.elm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ add attributes.
8989
9090
This works by using CSS selectors which are [globally scoped and
9191
bad for maintainability](https://medium.com/seek-blog/the-end-of-global-css-90d2a4a06284),
92-
so definitely avoid using this module on DOM structures you control!
92+
so definitely avoid using this module except when you specifically need to style
93+
third-party DOM nodes!
9394
9495
9596
# Global Styles

src/DEPRECATED/Css/Namespace.elm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ module DEPRECATED.Css.Namespace exposing (namespace)
55
66
# DEPRECATED
77
8-
This module relies on a `Basics.toString` implementation which will no longer
9-
exist in Elm 0.19, at which point this module will be removed from elm-css.
10-
Fortunately, `Html.Styled` makes namespacing unnecessary, so please use it instead!
8+
`Html.Styled` makes namespacing unnecessary, so please use it instead of This
9+
module! This module relies on a `Basics.toString` implementation which will no
10+
longer exist in Elm 0.19, so it will be removed in the next major release of elm-css.
1111
1212
1313
## Namespacing

src/Html/Styled.elm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ expect to use frequently will be closer to the top.
6161
6262
## Less Common Elements
6363
64+
@docs details, menu, menuitem, summary
65+
6466
6567
### Less Common Inputs
6668
@@ -100,10 +102,12 @@ import Html.Styled.Internal as Internal exposing (Classname, InternalAttribute(.
100102
import VirtualDom exposing (Node)
101103

102104

105+
{-| -}
103106
type alias Html msg =
104107
StyledHtml msg
105108

106109

110+
{-| -}
107111
type alias Attribute msg =
108112
InternalAttribute msg
109113

@@ -112,17 +116,20 @@ type alias Attribute msg =
112116
-- MAKING HTML VALUES --
113117

114118

119+
{-| -}
115120
node : String -> List (Attribute msg) -> List (Html msg) -> Html msg
116121
node elemType =
117122
Element elemType
118123

119124

125+
{-| -}
120126
text : String -> Html msg
121127
text str =
122128
VirtualDom.text str
123129
|> Unstyled
124130

125131

132+
{-| -}
126133
map : (a -> b) -> Html a -> Html b
127134
map transform html =
128135
case html of
@@ -143,6 +150,7 @@ map transform html =
143150
|> Unstyled
144151

145152

153+
{-| -}
146154
toUnstyled : Html msg -> Node msg
147155
toUnstyled html =
148156
case html of
@@ -156,6 +164,7 @@ toUnstyled html =
156164
Internal.unstyleKeyed elemType attributes children
157165

158166

167+
{-| -}
159168
fromUnstyled : Node msg -> StyledHtml msg
160169
fromUnstyled =
161170
Internal.Unstyled

0 commit comments

Comments
 (0)