Package Exports
- mithril-materialized
- mithril-materialized/esm
- mithril-materialized/index.css
- mithril-materialized/sass/components/_badges.scss
- mithril-materialized/sass/components/_buttons.scss
- mithril-materialized/sass/components/_cards.scss
- mithril-materialized/sass/components/_carousel.scss
- mithril-materialized/sass/components/_chips.scss
- mithril-materialized/sass/components/_collapsible.scss
- mithril-materialized/sass/components/_color-classes.scss
- mithril-materialized/sass/components/_color-variables.scss
- mithril-materialized/sass/components/_datepicker.scss
- mithril-materialized/sass/components/_dropdown.scss
- mithril-materialized/sass/components/_global.scss
- mithril-materialized/sass/components/_grid.scss
- mithril-materialized/sass/components/_icons-material-design.scss
- mithril-materialized/sass/components/_materialbox.scss
- mithril-materialized/sass/components/_modal.scss
- mithril-materialized/sass/components/_navbar.scss
- mithril-materialized/sass/components/_normalize.scss
- mithril-materialized/sass/components/_preloader.scss
- mithril-materialized/sass/components/_pulse.scss
- mithril-materialized/sass/components/_sidenav.scss
- mithril-materialized/sass/components/_slider.scss
- mithril-materialized/sass/components/_table_of_contents.scss
- mithril-materialized/sass/components/_tabs.scss
- mithril-materialized/sass/components/_tapTarget.scss
- mithril-materialized/sass/components/_timepicker.scss
- mithril-materialized/sass/components/_toast.scss
- mithril-materialized/sass/components/_tooltip.scss
- mithril-materialized/sass/components/_transitions.scss
- mithril-materialized/sass/components/_typography.scss
- mithril-materialized/sass/components/_variables.scss
- mithril-materialized/sass/components/_waves.scss
- mithril-materialized/sass/components/forms/_checkboxes.scss
- mithril-materialized/sass/components/forms/_file-input.scss
- mithril-materialized/sass/components/forms/_form-groups.scss
- mithril-materialized/sass/components/forms/_forms.scss
- mithril-materialized/sass/components/forms/_input-fields.scss
- mithril-materialized/sass/components/forms/_radio-buttons.scss
- mithril-materialized/sass/components/forms/_range.scss
- mithril-materialized/sass/components/forms/_select.scss
- mithril-materialized/sass/components/forms/_switches.scss
- mithril-materialized/sass/materialize.scss
- mithril-materialized/umd
Readme
mithril-materialized
A materialize-css library for the Mithril framework (tested with v2.0 and higher, but presumably, it should work with v1.1.6 too), making it easier to use a Materialize theme in your application. The main focus of this library is on creating Mithril components for the more complicated Materialize components.
Supported components:
- Buttons
- Button
- FlatButton
- RoundButton
- SubmitButton
- FloatingActionButton
- Inputs
- TextInput
- TextArea
- AutoComplete
- UrlInput
- EmailInput
- NumberInput
- ColorInput
- RangeInput
- Chips
- Pickers
- DatePicker
- TimePicker
- Selections
- Select
- Options
- RadioButtons
- Switch
- Dropdown
- Collections
- Basic, Link and Avatar Collections
- Collapsible or accordion
- Modals
- ModalPanel
- Miscellaneous
- Tabs
- MaterialBox
- Carousel
- Pagination
- Parallax
- Additional
- Label
- HelperText
- Not from Materialize-CSS
Version history
v1.2.0: Added Search select, a searchable select dropdown
v1.1.7: Added option to add style to InputCheckbox and Options
v0.17.1: bug fix
Selectcomponent also reacts when thecheckedIdproperty becomes undefined (previously, it would ignore it).
v0.17.0
- Breaking change:
OptionsandRadioButtonsused theinlineproperty to put items horizontally. This is actually not needed, and it has been removed. Instead, use thecheckboxClassto set the grid size of each cell.
v0.16.3
NumberInputadds support for thestepattribute, so you can use the number up/down to represent floats too.
v0.16.2
- Updated dependencies, fixed library vulnerabilities
v0.16.1
Select,Options, andRadioButtons: ThecheckedIdproperty can be used to change the selection inonupdatedynamically. Otherwise, it is treated the same asinitialValue(which is only processed inoninit). This allows you to dynamically update the selections without recreating the component.
v0.16.0
Selectdisabledstatus is computed dynamically in the view, not only inoninit.Select,Option,Radio,Kanban:onchangeis computed dynamically in the view, not only inoninit. As theonchangecreated a closure, new attributes were not always updated as expected.
v0.15.4
Paginationcomponent simplified implementation.
v0.15.3
- FIX:
Pickersdestroy themonremove.
v0.15.2
- FIX:
Paginationdid not properly compute the go forward disabled/enabled state.
v0.15.1
- FIX:
Paginationdid not highlight current item when item index exceeded size limit. Also updated example with actual routes.
v0.15.0
- NEW:
FloatingActionButtoncreated.
v0.14.14
- FIX:
Kanbantriggering too manyonchangemessages.
v0.14.12
- FIX:
Selectwhen usingmultiplekeeps the dropdown open, but re-initialize select when the options change.
v0.14.11
- FIX:
Kanbandid not triggeronChangewhen disabled, but with editable properties.
v0.14.10
- FIX:
Chipsdid not initialize properly whenonChangewas not specified (e.g. when disabled).
v0.14.9
- NEW:
PasswordInputcomponent to enter passwords.
v0.14.8
- FIX:
Tabscomponent selection did not work in Edge due to the way theselectfunction was implemented in materialize-css.
v0.14.7
- FIX:
Selectwhen usingmultiplekeeps the dropdown open,dropdownOptionsandclassesare passed on creation. Select,Options,RadiosuseinitialValueinstead ofcheckedId(which is deprecated but still working). The rationale is that the checked values are only read initially, when the component is created.
v0.14.5
- FIX:
OptionsandRadiosno longer useh6element for labels, so they behave more like other labels.
v0.14.4
- FIX:
OptionsandRadioButtonsdid not listen to thedisabledproperty.
v0.14.3
- When using a placeholder in an
inputfield, the label should be active.
v0.14.2
LinksCollectionsometimes created unwantedhrefattribute in links.
v0.14.1 Using Mithril v2
- Migrated backwards from Mithril v2.0.3 to v2.0.1 due to bugs in the released version.
- When
Collectionitems have anidproperty, theidproperty is used as key (e.g. for sorting the collection). You should not include akeyproperty directly in your item's data, as explained here.
v0.14.0 Using Mithril v2
- Upgrading all dependencies
Pickersnow triggeronchangewhen closing.- Replace all links
oncreate: m.route.linkwithm.route.Link.
v0.13.15 Patch
Selectremovedconsole.warnin library.- Updated
npmscripts.
v0.13.14 Enhancements
Dropdown: displayed text is truncated, so it doesn't overflow the button.Selectcan receive options, e.g.dropdownOptions: { container: document.body }to display it properly in aModal.Modalexamples added withSelectandDropdowncomponents.
v0.13.13 Bug fix related to mithril RC7
- FIX
Kanbankey usage and drag-n-drop behaviour
v0.13.12 Bug fix
OptionscheckboxClasswas not applied, so you could not align items properly.
v0.13.11 Enhancements
Chipscomponent can now have an optionallabel(title) andhelperText(under the input). Also the alignment has been fixed (the input used to be slightly wider than a regular input).
v0.13.10 Enhancement
- Added IIFE and ESM output builds
- Refactoring the code slightly
Chipsnow has a defaultclassName: col s12
v0.13.9 Enhancement
ModalPanelbuttons'onclickhandler now also receives the event, so you can prevent mithril from redrawing.ModalPanelhas a new handler,onCreatewhich can be used to receive the modal instance, so you can control it programmatically.
v0.13.8 Bug fix
Select, checkedId is evaluated in the view instead ofoninit.
v0.13.6 Minor updates
Dropdown,Kanban,TimePicker,DatePickercan be disabled.
v0.13.5 Minor updates
Dropdownid, if not supplied, caused confusion when multipleDropdownswere used on one page.Kanbanuses type information. New property,editableIds, which makes some properties also editable in the list view.
v0.13.0 Breaking changes
Selectcomponent now maintains the checkedIds internally, i.e. they are only processed duringoninit. This is to create consistent behaviour with theOptionsandRadioButtonscomponents.Select,Options,DropdownandRadioButtonsare no longer of the generic type, since IDs can only be strings or numbers.ISelectOptionis removed, and is replaced byIInputOption, making it easier to switch between a radios, select and options.Optionshas a propertycheckedId, similar toRadioButtonsandSelect, to specify the checked/selected IDs. This replaces theIInputOption.isCheckedproperty, which has been removed.
NEW
- Kanban: new component to render an editable list of items. Supports drag-and-drop between lists too, essentially allowing you to create a Kanban list. Hence the name.
InputCheckbox: label is optionalOptionsandRadioButtonsare more consistent with respect to look and feel.OptionsandRadioButtonssupport aninlineproperty to align them horizontally.Select,Options, andRadioButtonsall useIInputOptionto specify their options. An item can be disabled now.
v0.13.0 No breaking changes
FileInput: addedinitialValueto set the initial value more clearly, and added a clear button to remove the input.
v0.12.2 No breaking changes
Tabs: addedcontentClassto add a class to the content.
v0.12.1 No breaking changes
- Simplified bundling after issues in
webpack.
v0.12.0 No breaking changes
Tabscomponent added, to show tabs.
v0.11.11 No breaking changes
- Bug fix:
TextAreadid not invokeonchangewhen the input was cleared. - Using Rollup as bundler, generating two bundles (ESM, regular JS).
v0.11.8 No breaking changes
Collection onclickevent was not registered properly.
v0.11.7 No breaking changes
Timelinetitle can now be a Vnode too.
v0.11.6 No breaking changes
Selectcontrol can now be disabled by adding the propertydisabled: trueto the control's properties.
v0.11.5 No breaking changes
MapEditorhas anonchangecallback to notify changes to the properties collection.MapEditorallows you to set the column width (keyClass) for the key and value column (keyValue).
v0.11.4 No breaking changes
- FIX
CodeBlockmissed importing ofcss.
v0.11.3 No breaking changes
- FIX
Timeline: Default date formatter did not add 1 to the months. See here. - FIX
MapEditorwhen dealing with number inputs and the number was 0, it did not work properly. - FIX
NumberInputwhen the number was 0, the label was not active (and overlaying the number).
v0.11.2 No breaking changes
- FIX Issue with
SecondaryContentinCollectioncomponent: when nohrefwas provided, it still created ahref=#!undefinedlink.
v0.11.1 No breaking changes
- Improved generics of
SelectandDropdowncomponent - FIX Issue with
placeholderinSelectcomponent: when no item was selected, it would not show the placeholder text.
v0.11.0 New component, Timeline
- Added a
Timelinecomponent to render vertical timelines. Collectionnow accepts other parameters, e.g. styles.- All
cssstyles are extracted into separatecssfiles, and imported in the component. This implies that you don't need to add the required CSS in your own application anymore (except formaterialisecss, of course). - Added documentation using
Typedoc. It can be found here.
v0.10.0 New component, MapEditor
- Added a new component,
MapEditor, to edit a map of key-value pairs. InputCheckboxcan now be disabled.- Attributes are better dealt with and no longer end up as unused attributes of elements.
- Fixed a bug for
TextInput, where sometimes theactiveclass was not added even if theinputelement had a value.
v0.9.10 Breaking changes
- Deprecated the use of all
contentClassproperties in favour of the mithril conventionclassName.
v0.9.9 Breaking changes
ModalPanel: it's description (i.e. the main content area of the modal) can be aVnode.Selectdoes not usecontentClassanymore, but instead uses the regular mithrilclassName(but notclass, since this is a reserved keyword in TypeScript).
v0.9.6 No breaking changes
- For a
Collectionwith secondary content, do not create a SPA route (with a #!) but leave the URL as is.
v0.9.5 No breaking changes
- FIX
Selectbug when numeric option IDs were used and ID === 0, option was never selected.
v0.9.4 No breaking changes
- FIX
Collectionwithout headers did no longer render.
v0.9.3 No breaking changes
Collectionwith links can now also contain a header.Collectionwith no items and only a header will now just render the header
v0.9.0 Breaking changes
Collapsibleis now correctly spelled (used to beCollabsible, oops).- Added
Collection, to create a collection of items: supports basic, link and avatar collections.
v0.8.3 No breaking changes
FileInputcomponent can be disabled, and accepts file types.
v0.8.1 No breaking changes
- Closes issue #1: Select issue with id === 0
- MaterialBox can set height, passes attributes to wrapped image element
v0.8.0 No breaking changes
FileInputcomponent can specifyclassproperty on thedivwrapper (defaultcol s12) andcontentClassproperty on the file input element.
v0.7.0 Breaking changes for Dropdown component.
- New
FileInputcomponent to upload one or more files. Dropdownuses similar items asSelect, and usescheckedIdto select the item.Dropdownitems can now use an icon and dividers.Dropdowncan now have a helper text option and an icon prefix.
v0.6.4 Breaking changes, bug fix.
Selectdid not always return the proper id on selection changes with multiple elements.
v0.6.3 No breaking changes, bug fix.
Selectdid not update dynamically when checkedId changed.
v0.6.2 No breaking changes
Selectcan useM.FormSelectOptions.
v0.6.1 No breaking changes
Selectcan havedisabledoptions, andidis optional (in which case the label is used).Selectcan use a prefix icon.
v0.6.0 No breaking changes
Inputscan now useonkeyup,onkeydown, andonkeypressevents. They also return the value.- Additionally, they can use
readOnly,patternandautocomplete(does not always seem to work).
v0.5.0 No breaking changes
- NEW: Pagination control
- BUG FIX:
Input.onchangewould not fire if the input was cleared. - All options now derives from mithril's
Attributes. - Using
FactoryComponenttype
v0.4.4 No breaking changes
- Do not pass attributes through, e.g. if you had a
m(FlatButton, { onupdate }), theonupdatewas passed through to theHelperTexttoo.
v0.4.3 No breaking changes
- The validate method for inputs now also accepts the HTMLInputElement
- Removed a few left-over
console.logstatements.
v0.4.2 No breaking changes
- Added
requiredandaria-required="true"attributes when therequiredorisMandatoryproperty are set.
v0.4.1 No breaking changes
- Updated all components to use the mithril
domattribute instead of performing a document query. This has two advantages: first of all, performance, since we do not need to query for an element we already have. Second, when implementing custom elements that have anoncreatefunction. Using document.query... will lead to no results.
v0.4.0 No breaking changes
- New components: MaterialBox, Collapsible or accordion, and Carousel
v0.3.0 Breaking changes
- Buttons no longer use the
uiclass to specify additional properties likeonclick. Instead, you can leverage the mithril attributes directly. See the example,button-page. contentClasshas been removed in favour of the default mithrilclassorclassNameattribute.- The Icon function has been replaced by the
Iconcomponent. TheSmallIconandPrefixedIconhave been removed, as they can easily be created using theIconcomponent. - The
autofocusattribute for inputs now also works on updates (by calling the element.focus() method). - The code has been split over multiple files, so it is easier to only import the components that you need.
v0.2.2
- Validate function can return a custom validation message. Also, it is called in
onupdate, so the validation occurs also when you just attach the validate function conditionally.
v0.2.1
- Label field is optional for inputs.
- Added autofocus function|property to input fields.
- Added custom validation using the validate function|property to add valid/invalid label to an input.
- Removed dependency on materialize-css (it is expected that it is imported via the main app).
Usage instructions
See the documentation for examples on how to use this library in your own application. Please note that the library does not include mithril, nor the materialize-css JavaScript or CSS, so you have to include them yourself, as documented.
Build instructions
This repository consists of two packages, combined using lerna: the lib package that is published to npm, as well as an example project which uses this library to display the Mithril components that it contains.
To install the dependencies, you can use npm i, or, alternatively, use pnpm m i (assuming you have installed pnpm as alternative package manager using npm i -g pnpm) to perform a multi-repository install. Next, build everything using npm start and visit the documentation page on http://localhost:1234 in case port 1234 is not occupied already.
CSS
Although I've tried to limit the CSS adaptations to a minimum, I needed to tweak certain parts to make it look better. Here are the styles I've added.
/* For the switch */
.clear,
.clear-10,
.clear-15 {
clear: both;
/* overflow: hidden; Précaution pour IE 7 */
}
.clear-10 {
margin-bottom: 10px;
}
.clear-15 {
margin-bottom: 15px;
}
span.mandatory {
margin-left: 5px;
color: red;
}
label+.switch {
margin-top: 1rem;
}
/* For the color input */
input[type='color']:not(.browser-default) {
margin: 0px 0 8px 0;
/** Copied from input[type=number] */
background-color: transparent;
border: none;
border-bottom: 1px solid #9e9e9e;
border-radius: 0;
outline: none;
height: 3rem;
width: 100%;
font-size: 16px;
padding: 0;
-webkit-box-shadow: none;
box-shadow: none;
-webkit-box-sizing: content-box;
box-sizing: content-box;
-webkit-transition: border 0.3s, -webkit-box-shadow 0.3s;
transition: border 0.3s, -webkit-box-shadow 0.3s;
transition: box-shadow 0.3s, border 0.3s;
transition: box-shadow 0.3s, border 0.3s, -webkit-box-shadow 0.3s;
}
/* For the options' label */
.input-field.options > label {
top: -2.5rem;
}
/* For the code block */
.codeblock {
margin: 1.5rem 0 2.5rem 0;
}
.codeblock > div {
margin-bottom: 1rem;
}
.codeblock > label {
display: inline-block;
}