diff --git a/packages/checkbox/README.md b/packages/checkbox/README.md index 7a4e1473166..f5c709ed771 100644 --- a/packages/checkbox/README.md +++ b/packages/checkbox/README.md @@ -1,64 +1,138 @@ -# mwc-checkbox +# `` [![Published on npm](https://img.shields.io/npm/v/@material/mwc-checkbox.svg)](https://www.npmjs.com/package/@material/mwc-checkbox) +> IMPORTANT: The Material Web Components are a work in progress and subject to +> major changes until 1.0 release. + +Checkboxes allow the user to select one or more items from a set. Checkboxes can +be used to turn an option on or off. + +[Material Design Guidelines: Checkboxes](https://material.io/components/selection-controls/#checkboxes) + +## Installation -> :warning: These components are a work in progress. They are pre-release and should be considered experimental, as they may undergo major changes before release. We are experimenting with alternate architectures and approaches with the goal of allowing us to bring the most correct and optimal implementation of Material components to the widest possible audiences. Visible progress may be slow, as this research is across teams and repositories so is not consistently reflected in commits to this codebase. :warning: +```sh +npm install @material/mwc-checkbox +``` + +> NOTE: The Material Web Components are distributed as ES2017 JavaScript +> Modules, and use the Custom Elements API. They are compatible with all modern +> browsers including Chrome, Firefox, Safari, Edge, and IE11, but an additional +> tooling step is required to resolve *bare module specifiers*, as well as +> transpilation and polyfills for Edge and IE11. See +> [here](https://github.com/material-components/material-components-web-components#quick-start) +> for detailed instructions. -A [Material Components](https://material.io/components/) icon implementation using [Web Components](https://www.webcomponents.org/introduction) +## Example usage -## Getting started +### Standard - * The easiest way to try out mwc-checkbox is to use one of these online tools: + - * Runs in all [supported](#supported-browsers) browsers: [StackBlitz](https://stackblitz.com/edit/mwc-checkbox-example?file=index.js), [Glitch](https://glitch.com/edit/#!/mwc-checkbox-example?path=index.html) +```html + - * Runs in browsers with [JavaScript Modules](https://caniuse.com/#search=modules): [JSBin](https://jsbin.com/qobefic/edit?html,output), - [CodePen](https://codepen.io/jcrestel/pen/KGWBLd). + +``` -* When you're ready to use mwc-checkbox in a project, install it via [npm](https://www.npmjs.com/). To run the project in the browser, a module-compatible toolctain is required. We recommend installing the [Polymer CLI](https://github.com/Polymer/polymer-cli) and using its development server as follows. +### Standard, disabled, and custom styles - 1. Ensure the webcomponents polyfills are included in your HTML page + - - Install webcomponents polyfills +```html +
+ + + +
- ```npm i @webcomponents/webcomponentsjs``` +
+ + + +
- - Add webcomponents polyfills to your HTML page +
+ + + + +
+``` - `````` +### Labels - 1. Add mwc-checkbox to your project: +Most applications should use +[``](https://github.com/material-components/material-components-web-components/tree/master/packages/formfield) +to associate an interactive label with the checkbox. - ```npm i @material/mwc-checkbox``` + - 1. Import the mwc-checkbox definition into your HTML page: +```html + - `````` + + + - Or into your module script: + + + - ```import {Checkbox} from "@material/mwc-checkbox"``` + + + - 1. Create an instance of mwc-checkbox in your HTML page, or via any framework that [supports rendering Custom Elements](https://custom-elements-everywhere.com/): + +``` - `````` +## API - 1. Install the Polymer CLI: +### Properties/Attributes - ```npm i -g polymer-cli``` +Name | Type | Default | Description +--------------- | --------- | ------- | ----------- +`checked` | `boolean` | `false` | Whether the checkbox is checked. +`indeterminate` | `boolean` | `false` | When a checkbox is the parent of a set of child checkboxes, the *indeterminate* state is used on the parent to indicate that some but not all of its children are checked. +`disabled` | `boolean` | `false` | When `true`, the checkbox cannot be interacted with, and renders in muted colors. +`value` | `string` | `''` | The value that will included if the checkbox is submitted in a form. - 1. Run the development server and open a browser pointing to its URL: - ```polymer serve``` +### Methods - > mwc-checkbox is published on [npm](https://www.npmjs.com/package/@material/mwc-checkbox) using JavaScript Modules. - This means it can take advantage of the standard native JavaScript module loader available in all current major browsers. - > - > However, since mwc-checkbox uses npm convention to reference dependencies by name, a light transform to rewrite specifiers to URLs is required to get it to run in the browser. The polymer-cli's development server `polymer serve` automatically handles this transform. +*None* - Tools like [WebPack](https://webpack.js.org/) and [Rollup](https://rollupjs.org/) can also be used to serve and/or bundle mwc-checkbox. +### Events -## Supported Browsers +| Event Name | Target | Detail | Description +| ---------- | -------------- | ------ | ----------- +| `change` | `mwc-checkbox` | `{}` | Fired when the user modifies the checkbox `checked` or `indeterminate` states from an input device interaction. Note that, like [native ``](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event), the `change` event is *not* fired when the `checked` or `indeterminate` properties are set from JavaScript. -The last 2 versions of all modern browsers are supported, including -Chrome, Safari, Opera, Firefox, Edge. In addition, Internet Explorer 11 is also supported. \ No newline at end of file +### CSS Custom Properties + + +| Name | Default | Description | +| ----------------------- | --------- | ----------------------------------- | +| `--mdc-theme-secondary` | ![](images/color_018786.png) `#018786` | Background color when the checkbox is `checked` or `indeterminate`, and the base color of the ripple effect and focus halo. + +## Additional references + +- [MDC Web Checkboxes](https://material.io/develop/web/components/input-controls/checkboxes/) diff --git a/packages/checkbox/images/checked.png b/packages/checkbox/images/checked.png new file mode 100644 index 00000000000..96ca7e3cbeb Binary files /dev/null and b/packages/checkbox/images/checked.png differ diff --git a/packages/checkbox/images/color_018786.png b/packages/checkbox/images/color_018786.png new file mode 100644 index 00000000000..7eda3f329f9 Binary files /dev/null and b/packages/checkbox/images/color_018786.png differ diff --git a/packages/checkbox/images/formfield.png b/packages/checkbox/images/formfield.png new file mode 100644 index 00000000000..c6fb636eaf6 Binary files /dev/null and b/packages/checkbox/images/formfield.png differ diff --git a/packages/checkbox/images/standard_disabled_styled.png b/packages/checkbox/images/standard_disabled_styled.png new file mode 100644 index 00000000000..e04257c14db Binary files /dev/null and b/packages/checkbox/images/standard_disabled_styled.png differ