Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fab): Made initRipple and unbounded props optional #810

Closed
wants to merge 12 commits into from
Closed
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Component | Spec | MDC Web

## Getting Started

### With StackBlitz

If you're looking to see how it looks without having to install a bunch of npm modules in your environment, please have a look at this [Starter Stackblitz](https://stackblitz.com/edit/react-eeyij6).

### With create-react-app

`create-react-app` is a popular CLI tool to getting started with React. If you're new to React or Webpack, you might be starting out here. This section will walk you through configuring `create-react-app` to install and use our components.
Expand Down
5 changes: 0 additions & 5 deletions docs/best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,4 @@ Since `[email protected]` is exporting `default`, we should be importing as such:
```ts
// referenced in https://github.com/basarat/typescript-book/blob/master/docs/project/external-modules.md#default-exportsimports
import classnames from 'classnames';
```

In other cases where we import modules that do not use `default`, we should import like:
```ts
import * as classnames from 'classnames';
```
3,026 changes: 2,446 additions & 580 deletions package-lock.json

Large diffs are not rendered by default.

64 changes: 30 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
"stop": "./test/screenshot/stop.sh",
"build": "npm run clean && mkdirp build && node --max_old_space_size=8192 node_modules/.bin/webpack --config packages/webpack.config.js --progress --colors",
"capture": "MDC_COMMIT_HASH=$(git rev-parse --short HEAD) MDC_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) mocha --require ts-node/register --require babel-core/register --ui tdd --timeout 30000 test/screenshot/capture-suite.tsx",
"clean": "rimraf build/** build packages/**/dist/",
"clean": "rimraf build/** build packages/*/dist/",
"commitmsg": "validate-commit-msg",
"fix": "eslint --fix --ext .jsx,.js,.tsx,.ts packages test",
"lint": "eslint --ext .jsx,.js,.tsx,.ts packages test",
"pretest": "npm stop",
"test": "npm run lint && npm run test:unit && npm run test:screenshots",
"posttest": "npm stop && istanbul report --root coverage text-summary && istanbul check-coverage --lines 95 --statements 95 --branches 95 --functions 95",
"postinstall": "lerna bootstrap",
"postinstall": "lerna bootstrap && rm node_modules/**/.babelrc -f && rm packages/**/node_modules/.babelrc -f",
"test:watch": "karma start karma.local.js --auto-watch",
"test:unit": "npm run clean && cross-env NODE_ENV=test karma start karma.local.js --single-run",
"test:unit-ci": "karma start karma.ci.js --single-run",
Expand All @@ -41,9 +41,11 @@
"linear-progress",
"list",
"menu-surface",
"notched-outline",
"radio",
"ripple",
"select",
"snackbar",
"top-app-bar",
"switch",
"tab",
Expand All @@ -60,34 +62,27 @@
},
"devDependencies": {
"@google-cloud/storage": "^1.6.0",
"@material/button": "^0.43.0",
"@material/card": "^0.41.0",
"@material/checkbox": "^0.41.0",
"@material/chips": "^0.41.0",
"@material/dialog": "^0.43.0",
"@material/dom": "^0.41.0",
"@material/drawer": "^0.41.0",
"@material/fab": "^0.41.0",
"@material/floating-label": "^0.41.0",
"@material/icon-button": "^0.41.0",
"@material/layout-grid": "^0.41.0",
"@material/line-ripple": "^0.41.0",
"@material/linear-progress": "^0.41.0",
"@material/list": "^0.41.0",
"@material/menu-surface": "^0.41.0",
"@material/notched-outline": "^0.41.0",
"@material/radio": "^0.41.0",
"@material/ripple": "^0.41.0",
"@material/select": "^0.40.1",
"@material/snackbar": "^0.43.0",
"@material/switch": "^0.41.0",
"@material/tab": "^0.41.0",
"@material/tab-bar": "^0.41.0",
"@material/tab-indicator": "^0.41.0",
"@material/tab-scroller": "^0.41.0",
"@material/textfield": "^0.41.0",
"@material/top-app-bar": "^0.41.0",
"@material/typography": "^0.41.0",
"@material/base": "^1.0.0",
"@material/button": "^1.1.0",
"@material/card": "^1.1.0",
"@material/checkbox": "^1.0.0",
"@material/chips": "^1.1.1",
"@material/dialog": "^1.1.0",
"@material/drawer": "^1.0.1",
"@material/floating-label": "^1.1.0",
"@material/icon-button": "^1.1.0",
"@material/line-ripple": "^1.0.0",
"@material/list": "1.0.0",
"@material/menu-surface": "^1.0.1",
"@material/notched-outline": "^1.1.1",
"@material/radio": "^1.1.0",
"@material/ripple": "^1.0.0",
"@material/select": "^1.1.1",
"@material/snackbar": "^1.0.0",
"@material/tab": "^1.0.0",
"@material/tab-bar": "^1.0.0",
"@material/textfield": "^1.1.1",
"@material/typography": "^1.0.0",
"@types/chai": "^4.1.7",
"@types/classnames": "^2.2.6",
"@types/enzyme": "^3.1.15",
Expand Down Expand Up @@ -119,8 +114,9 @@
"cp-file": "^6.0.0",
"cross-env": "^5.2.0",
"css-loader": "^0.28.10",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.11.2",
"enzyme-adapter-utils": "^1.10.1",
"eslint": "^5.9.0",
"eslint-config-google": "^0.9.1",
"eslint-plugin-react": "^7.7.0",
Expand All @@ -146,13 +142,13 @@
"react-dom": "^16.4.2",
"react-router-dom": "^4.3.1",
"remap-istanbul": "^0.12.0",
"rimraf": "^2.6.3",
"resemblejs": "^3.0.1",
"rimraf": "^2.6.3",
"sass-loader": "^6.0.7",
"testdouble": "^3.6.0",
"ts-loader": "^3.5.0",
"ts-node": "^7.0.1",
"typescript": "^3.2.2",
"typescript": "^3.3.3",
"typescript-eslint-parser": "^21.0.1",
"utility-types": "^2.1.0",
"uuid": "^3.3.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import * as React from 'react';
import React from 'react';
import classnames from 'classnames';
import * as Ripple from '@material/react-ripple';
import {withRipple, InjectedProps} from '@material/react-ripple';

const BUTTON_CLASS_NAME = 'mdc-button__icon';

type ButtonTypes = HTMLAnchorElement | HTMLButtonElement;

export interface ButtonProps<T extends ButtonTypes>
extends Ripple.InjectedProps<T>, React.AnchorHTMLAttributes<T>, React.ButtonHTMLAttributes<T> {
extends InjectedProps<T>, React.AnchorHTMLAttributes<T>, React.ButtonHTMLAttributes<T> {
raised?: boolean;
unelevated?: boolean;
outlined?: boolean;
Expand Down Expand Up @@ -109,5 +109,5 @@ Button.defaultProps = {
initRipple: () => {},
};

export default Ripple.withRipple<ButtonProps<ButtonTypes>, ButtonTypes>(Button);
export default withRipple<ButtonProps<ButtonTypes>, ButtonTypes>(Button);

2 changes: 1 addition & 1 deletion packages/button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"url": "https://github.com/material-components/material-components-web-react.git"
},
"dependencies": {
"@material/button": "^0.43.0",
"@material/button": "^1.1.0",
"@material/react-ripple": "^0.11.0",
"classnames": "^2.2.6",
"react": "^16.4.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/card/ActionButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import * as React from 'react';
import React from 'react';
import classnames from 'classnames';

type ChildType = React.ReactElement<React.HTMLProps<HTMLButtonElement|HTMLAnchorElement>>;
Expand Down
2 changes: 1 addition & 1 deletion packages/card/ActionIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import * as React from 'react';
import React from 'react';
import classnames from 'classnames';

type ChildType = React.ReactElement<React.HTMLProps<HTMLImageElement|HTMLOrSVGElement>>;
Expand Down
2 changes: 1 addition & 1 deletion packages/card/Actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import * as React from 'react';
import React from 'react';
import classnames from 'classnames';

export interface ActionsProps extends React.HTMLProps<HTMLDivElement> {
Expand Down
2 changes: 1 addition & 1 deletion packages/card/Media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import * as React from 'react';
import React from 'react';
import classnames from 'classnames';

export interface MediaProps extends React.HTMLProps<HTMLDivElement> {
Expand Down
8 changes: 4 additions & 4 deletions packages/card/PrimaryContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import * as React from 'react';
import React from 'react';
import classnames from 'classnames';
import * as Ripple from '@material/react-ripple';
import {withRipple, InjectedProps} from '@material/react-ripple';

export interface PrimaryContentBaseProps extends React.HTMLProps<HTMLDivElement>, Ripple.InjectedProps<HTMLDivElement>{
export interface PrimaryContentBaseProps extends React.HTMLProps<HTMLDivElement>, InjectedProps<HTMLDivElement>{
className: string;
unbounded?: boolean;
};
Expand All @@ -47,4 +47,4 @@ export const PrimaryContentBase: React.FunctionComponent<PrimaryContentBaseProps
);
};

export default Ripple.withRipple<PrimaryContentBaseProps, HTMLDivElement>(PrimaryContentBase);
export default withRipple<PrimaryContentBaseProps, HTMLDivElement>(PrimaryContentBase);
2 changes: 1 addition & 1 deletion packages/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import * as React from 'react';
import React from 'react';
import classnames from 'classnames';
import ActionButtons from './ActionButtons';
import ActionIcons from './ActionIcons';
Expand Down
2 changes: 1 addition & 1 deletion packages/card/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"url": "https://github.com/material-components/material-components-web-react.git"
},
"dependencies": {
"@material/card": "^0.41.0",
"@material/card": "^1.1.0",
"@material/react-ripple": "^0.11.0",
"classnames": "^2.2.6",
"react": "^16.4.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/checkbox/NativeControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import * as React from 'react';
import React from 'react';

export interface NativeControlProps extends React.HTMLProps<HTMLInputElement>{
checked: boolean;
Expand Down
43 changes: 26 additions & 17 deletions packages/checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import * as React from 'react';
import React from 'react';
import classnames from 'classnames';
// @ts-ignore no mdc .d.ts file
import {MDCCheckboxFoundation, MDCCheckboxAdapter} from '@material/checkbox/dist/mdc.checkbox';
import * as Ripple from '@material/react-ripple';
import {MDCCheckboxFoundation} from '@material/checkbox/foundation';
import {MDCCheckboxAdapter} from '@material/checkbox/adapter';
import {cssClasses} from '@material/checkbox/constants';
import {withRipple, InjectedProps} from '@material/react-ripple';

import NativeControl from './NativeControl';

export interface CheckboxProps extends Ripple.InjectedProps<HTMLDivElement, HTMLInputElement> {
export interface CheckboxProps extends InjectedProps<HTMLDivElement, HTMLInputElement> {
checked?: boolean;
className?: string;
disabled?: boolean;
Expand All @@ -45,20 +46,22 @@ interface CheckboxState {
checked?: boolean;
indeterminate?: boolean;
classList: Set<string>;
'aria-checked': boolean;
'aria-checked': string;
disabled: boolean;
};

export class Checkbox extends React.Component<CheckboxProps, CheckboxState> {
inputElement: React.RefObject<HTMLInputElement> = React.createRef();
foundation = MDCCheckboxFoundation;
foundation!: MDCCheckboxFoundation;

constructor(props: CheckboxProps) {
super(props);
this.state = {
'checked': props.checked,
'indeterminate': props.indeterminate,
'classList': new Set(),
'aria-checked': false,
'aria-checked': 'false',
'disabled': props.disabled!,
};
}

Expand All @@ -74,7 +77,7 @@ export class Checkbox extends React.Component<CheckboxProps, CheckboxState> {
componentDidMount() {
this.foundation = new MDCCheckboxFoundation(this.adapter);
this.foundation.init();
this.foundation.setDisabled(this.props.disabled);
this.foundation.setDisabled(this.props.disabled!);
// indeterminate property on checkboxes is not supported:
// https://github.com/facebook/react/issues/1798#issuecomment-333414857
if (this.inputElement.current) {
Expand All @@ -91,7 +94,7 @@ export class Checkbox extends React.Component<CheckboxProps, CheckboxState> {
this.handleChange(checked!, indeterminate!);
}
if (disabled !== prevProps.disabled) {
this.foundation.setDisabled(disabled);
this.foundation.setDisabled(disabled!);
}
}

Expand All @@ -118,7 +121,9 @@ export class Checkbox extends React.Component<CheckboxProps, CheckboxState> {
get classes(): string {
const {classList} = this.state;
const {className} = this.props;
return classnames('mdc-checkbox', Array.from(classList), className);
return classnames(
'mdc-checkbox', Array.from(classList),
this.state.disabled ? cssClasses.DISABLED : null, className);
}

updateState = (key: keyof CheckboxState, value: string | boolean) => {
Expand Down Expand Up @@ -146,10 +151,14 @@ export class Checkbox extends React.Component<CheckboxProps, CheckboxState> {
// isAttachedToDOM will likely be removed
// https://github.com/material-components/material-components-web/issues/3691
isAttachedToDOM: () => true,
isChecked: () => this.state.checked,
isIndeterminate: () => this.state.indeterminate,
isChecked: () => this.state.checked!,
isIndeterminate: () => this.state.indeterminate!,
setNativeControlAttr: this.updateState,
setNativeControlDisabled: (disabled) => {
this.updateState('disabled', disabled);
},
removeNativeControlAttr: this.removeState,
forceLayout: () => null,
};
}

Expand All @@ -169,8 +178,8 @@ export class Checkbox extends React.Component<CheckboxProps, CheckboxState> {
initRipple,
onChange,
unbounded,
/* eslint-enable no-unused-vars */
disabled,
/* eslint-enable no-unused-vars */
nativeControlId,
name,
...otherProps
Expand All @@ -186,8 +195,8 @@ export class Checkbox extends React.Component<CheckboxProps, CheckboxState> {
<NativeControl
id={nativeControlId}
checked={this.state.checked}
disabled={disabled}
aria-checked={this.state['aria-checked']}
disabled={this.state.disabled}
aria-checked={(this.state['aria-checked'] || this.state.checked!.toString()) as ('true' | 'false')}
name={name}
onChange={this.onChange}
rippleActivatorRef={this.inputElement}
Expand All @@ -211,4 +220,4 @@ export class Checkbox extends React.Component<CheckboxProps, CheckboxState> {
}
}

export default Ripple.withRipple<CheckboxProps, HTMLDivElement, HTMLInputElement>(Checkbox);
export default withRipple<CheckboxProps, HTMLDivElement, HTMLInputElement>(Checkbox);
2 changes: 1 addition & 1 deletion packages/checkbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"url": "https://github.com/material-components/material-components-web-react.git"
},
"dependencies": {
"@material/checkbox": "^0.41.0",
"@material/checkbox": "^1.1.0",
"@material/react-ripple": "^0.11.0",
"classnames": "^2.2.6",
"react": "^16.3.2"
Expand Down
Loading