We have a team of developers who create standard css-classes with tailwind.css which is generally used for Vue/React components. However, we are trying to use elm for a new project and would like to use the same classes from a js-file, as they are being maintained.
How should one import from javascript-file:
export const card = {
cardSelected: 'bg-blue-50',
cardOutline: 'f-card-outline absolute rounded-8 inset-0 transition-all border-2',
};
export const toaster = {
toasterContainer: 'fixed fixed-ios-fix bottom-16 left-0 right-0 mx-8',
toaster: 'f-toaster grid f-grid auto-rows-auto',
};
Such that those styles gets set on an element. E.g with toaster:
div [class 'f-toaster grid f-grid auto-rows-auto'][]
CodePudding user response:
You should be able to accomplish this with flags
.
On your js file you could have:
const app = Elm.Main.init({
node: document.getElementById('main'),
flags: {
card: {
cardSelected: 'bg-blue-50',
cardOutline: 'f-card-outline absolute rounded-8 inset-0 transition-all border-2',
}
}
})
and your Main.elm
would look something like this:
type alias CardValues =
{ cardSelected : String
, cardOutline : String
}
type alias Card =
{ card : CardValues }
type alias Model =
{ flags : Card }
main : Program Card Model Msg
main =
Browser.element
{ init = \flags -> ( { flags = flags }, Cmd.none )
, view =
\model ->
Html.div
[ Html.class model.flags.card.cardOutline ]
[ Html.h1 [] [ Html.text "Here!" ] ]
, update = \_ model -> ( model, Cmd.none )
, subscriptions = \_ -> Sub.none
}