Skip to content

Commit

Permalink
Add Framer X wrapper components (mui#17797)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrookes authored Nov 6, 2019
1 parent 65d1621 commit 6f7318c
Show file tree
Hide file tree
Showing 76 changed files with 11,372 additions and 24 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# The best pattern people should follow is ignoring the editors' files in their
# global .gitignore configuration file.
# However, in order to prevent issues. We also ignore editors' files here.
# The best pattern to follow is ignoring editor files in a global .gitignore configuration file.
# However, in order to prevent issues, editor files are ignored here.
.idea
.vscode

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/api/checkbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ You can learn more about the difference by [reading this guide](/guides/minimizi
| <span class="prop-name">checkedIcon</span> | <span class="prop-type">node</span> | <span class="prop-default">&lt;CheckBoxIcon /></span> | The icon to display when the component is checked. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
| <span class="prop-name">color</span> | <span class="prop-type">'primary'<br>&#124;&nbsp;'secondary'<br>&#124;&nbsp;'default'</span> | <span class="prop-default">'secondary'</span> | The color of the component. It supports those theme colors that make sense for this component. |
| <span class="prop-name">disabled</span> | <span class="prop-type">bool</span> | | If `true`, the switch will be disabled. |
| <span class="prop-name">disabled</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the switch will be disabled. |
| <span class="prop-name">disableRipple</span> | <span class="prop-type">bool</span> | | If `true`, the ripple effect will be disabled. |
| <span class="prop-name">icon</span> | <span class="prop-type">node</span> | <span class="prop-default">&lt;CheckBoxOutlineBlankIcon /></span> | The icon to display when the component is unchecked. |
| <span class="prop-name">id</span> | <span class="prop-type">string</span> | | The id of the `input` element. |
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/api/list-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Uses an additional container component if `ListItemSecondaryAction` is the last
| <span class="prop-name">component</span> | <span class="prop-type">elementType</span> | | The component used for the root node. Either a string to use a DOM element or a component. By default, it's a `li` when `button` is `false` and a `div` when `button` is `true`. |
| <span class="prop-name">ContainerComponent</span> | <span class="prop-type">elementType</span> | <span class="prop-default">'li'</span> | The container component used when a `ListItemSecondaryAction` is the last child. |
| <span class="prop-name">ContainerProps</span> | <span class="prop-type">object</span> | <span class="prop-default">{}</span> | Props applied to the container component if used. |
| <span class="prop-name">dense</span> | <span class="prop-type">bool</span> | | If `true`, compact vertical padding designed for keyboard and mouse input will be used. |
| <span class="prop-name">dense</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, compact vertical padding designed for keyboard and mouse input will be used. |
| <span class="prop-name">disabled</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the list item will be disabled. |
| <span class="prop-name">disableGutters</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the left and right padding is removed. |
| <span class="prop-name">divider</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, a 1px light border is added to the bottom of the list item. |
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/api/radio.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ You can learn more about the difference by [reading this guide](/guides/minimizi
| <span class="prop-name">checkedIcon</span> | <span class="prop-type">node</span> | | The icon to display when the component is checked. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
| <span class="prop-name">color</span> | <span class="prop-type">'primary'<br>&#124;&nbsp;'secondary'<br>&#124;&nbsp;'default'</span> | <span class="prop-default">'secondary'</span> | The color of the component. It supports those theme colors that make sense for this component. |
| <span class="prop-name">disabled</span> | <span class="prop-type">bool</span> | | If `true`, the switch will be disabled. |
| <span class="prop-name">disabled</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the switch will be disabled. |
| <span class="prop-name">disableRipple</span> | <span class="prop-type">bool</span> | | If `true`, the ripple effect will be disabled. |
| <span class="prop-name">icon</span> | <span class="prop-type">node</span> | | The icon to display when the component is unchecked. |
| <span class="prop-name">id</span> | <span class="prop-type">string</span> | | The id of the `input` element. |
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/api/switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ You can learn more about the difference by [reading this guide](/guides/minimizi
| <span class="prop-name">checkedIcon</span> | <span class="prop-type">node</span> | | The icon to display when the component is checked. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
| <span class="prop-name">color</span> | <span class="prop-type">'primary'<br>&#124;&nbsp;'secondary'<br>&#124;&nbsp;'default'</span> | <span class="prop-default">'secondary'</span> | The color of the component. It supports those theme colors that make sense for this component. |
| <span class="prop-name">disabled</span> | <span class="prop-type">bool</span> | | If `true`, the switch will be disabled. |
| <span class="prop-name">disabled</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the switch will be disabled. |
| <span class="prop-name">disableRipple</span> | <span class="prop-type">bool</span> | | If `true`, the ripple effect will be disabled. |
| <span class="prop-name">edge</span> | <span class="prop-type">'start'<br>&#124;&nbsp;'end'<br>&#124;&nbsp;false</span> | <span class="prop-default">false</span> | If given, uses a negative margin to counteract the padding on one side (this is often helpful for aligning the left or right side of the icon with content above or below, without ruining the border size and shape). |
| <span class="prop-name">icon</span> | <span class="prop-type">node</span> | | The icon to display when the component is unchecked. |
Expand Down
10 changes: 5 additions & 5 deletions docs/pages/api/text-field.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ For advanced cases, please look at the source of TextField by clicking on the
| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| <span class="prop-name">autoComplete</span> | <span class="prop-type">string</span> | | This prop helps users to fill forms faster, especially on mobile devices. The name can be confusing, as it's more like an autofill. You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill). |
| <span class="prop-name">autoFocus</span> | <span class="prop-type">bool</span> | | If `true`, the `input` element will be focused during the first mount. |
| <span class="prop-name">autoFocus</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the `input` element will be focused during the first mount. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
| <span class="prop-name">color</span> | <span class="prop-type">'primary'<br>&#124;&nbsp;'secondary'</span> | <span class="prop-default">'primary'</span> | The color of the component. It supports those theme colors that make sense for this component. |
| <span class="prop-name">defaultValue</span> | <span class="prop-type">any</span> | | The default value of the `input` element. |
| <span class="prop-name">disabled</span> | <span class="prop-type">bool</span> | | If `true`, the `input` element will be disabled. |
| <span class="prop-name">error</span> | <span class="prop-type">bool</span> | | If `true`, the label will be displayed in an error state. |
| <span class="prop-name">disabled</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the `input` element will be disabled. |
| <span class="prop-name">error</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the label will be displayed in an error state. |
| <span class="prop-name">FormHelperTextProps</span> | <span class="prop-type">object</span> | | Props applied to the [`FormHelperText`](/api/form-helper-text/) element. |
| <span class="prop-name">fullWidth</span> | <span class="prop-type">bool</span> | | If `true`, the input will take up the full width of its container. |
| <span class="prop-name">fullWidth</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the input will take up the full width of its container. |
| <span class="prop-name">helperText</span> | <span class="prop-type">node</span> | | The helper text content. |
| <span class="prop-name">id</span> | <span class="prop-type">string</span> | | The id of the `input` element. Use this prop to make `label` and `helperText` accessible for screen readers. |
| <span class="prop-name">InputLabelProps</span> | <span class="prop-type">object</span> | | Props applied to the [`InputLabel`](/api/input-label/) element. |
Expand All @@ -70,7 +70,7 @@ For advanced cases, please look at the source of TextField by clicking on the
| <span class="prop-name">inputRef</span> | <span class="prop-type">ref</span> | | Pass a ref to the `input` element. |
| <span class="prop-name">label</span> | <span class="prop-type">node</span> | | The label content. |
| <span class="prop-name">margin</span> | <span class="prop-type">'none'<br>&#124;&nbsp;'dense'<br>&#124;&nbsp;'normal'</span> | | If `dense` or `normal`, will adjust vertical spacing of this and contained components. |
| <span class="prop-name">multiline</span> | <span class="prop-type">bool</span> | | If `true`, a textarea element will be rendered instead of an input. |
| <span class="prop-name">multiline</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, a textarea element will be rendered instead of an input. |
| <span class="prop-name">name</span> | <span class="prop-type">string</span> | | Name attribute of the `input` element. |
| <span class="prop-name">onChange</span> | <span class="prop-type">func</span> | | Callback fired when the value is changed.<br><br>**Signature:**<br>`function(event: object) => void`<br>*event:* The event source of the callback. You can pull out the new value by accessing `event.target.value` (string). |
| <span class="prop-name">placeholder</span> | <span class="prop-type">string</span> | | The short hint displayed in the input before the user enters a value. |
Expand Down
8 changes: 4 additions & 4 deletions docs/src/modules/utils/defaultPropsHandler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as astTypes from 'ast-types';
import { utils as docgenUtils } from 'react-docgen';
const astTypes = require('ast-types');
const { utils: docgenUtils } = require('react-docgen');

const { getPropertyName, isReactForwardRefCall, printValue, resolveToValue } = docgenUtils;

Expand Down Expand Up @@ -81,10 +81,10 @@ function getPropsPath(functionBody) {
return propsPath;
}

export default function defaultPropsHandler(documentation, componentDefinition) {
module.exports = function defaultPropsHandler(documentation, componentDefinition) {
const renderBody = getRenderBody(componentDefinition);
const props = getPropsPath(renderBody);
if (props !== undefined) {
getDefaultValuesFromProps(props.get('properties'), documentation);
}
}
};
3 changes: 3 additions & 0 deletions framer/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Material-UI.framerfx/design/*
Material-UI.framerfx/build/*
canvas.tsx
9 changes: 9 additions & 0 deletions framer/Material-UI.framerfx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build
.backups
.cache
.project.log
yarn-error.log
.yarnrc
.framer-lock
canvas.tsx
dist
3 changes: 3 additions & 0 deletions framer/Material-UI.framerfx/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@framer:registry=https://registry.framer.com/
always-auth=true
//registry.framer.com/:_authToken=f326029a-e8b0-43b7-a65d-9cb1ff2de882
58 changes: 58 additions & 0 deletions framer/Material-UI.framerfx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Material-UI

This is the official resource for Material-UI React components in Framer.

## Supported components

The following components are currently supported:

- App bar
- Avatar
- Badge
- Bottom navigation
- Button
- Checkbox
- Chip
- Circular progress
- Floating action button (Fab)
- Icon (all 1100+ Material Icons in 5 themes, plus social icons)
- Icon button (with optional badge)
- Linear progress
- List
- List item
- Media card
- Paper
- Radio
- Radio group
- Slider
- Snackbar content
- Switch
- Tabs
- Text field
- Theme (to globally set primary, secondary and error colors)
- Typography

## Usage

### Icons

Icons can be specified using either snake_case (as documented on material.io),
or PascalCase, as used in [the Material-UI documentation](https://material-ui.com/components/material-icons/).
Simply type the icon name in the appropriate property control.

The icon theme can be chosen from the related select field.

### Children

Where a component (such as Avatar) accepts a variety of child types, these can be configured through Framer property controls.
If multiple options are supplied, they take the following priority:

- Local image
- Image URL
- Icon
- Text

## Resources

- [Material-UI documentation](https://material-ui.com/)
- [GitHub repo](https://github.com/mui-org/material-ui/tree/master/framer)
114 changes: 114 additions & 0 deletions framer/Material-UI.framerfx/code/AppBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import * as React from 'react';
import { PropertyControls, ControlType } from 'framer';
// tslint:disable-next-line: ban-ts-ignore
// @ts-ignore
import MuiAppBar from '@material-ui/core/AppBar';
// tslint:disable-next-line: ban-ts-ignore
// @ts-ignore
import Toolbar from '@material-ui/core/Toolbar';
// tslint:disable-next-line: ban-ts-ignore
// @ts-ignore
import Typography from '@material-ui/core/Typography';
// tslint:disable-next-line: ban-ts-ignore
// @ts-ignore
import Button from '@material-ui/core/Button';
import { IconButton } from './IconButton';

// Define type of property
interface Props {
title?: string;
leftIcon?: string;
icon1?: string;
icon1Badge?: string;
icon2?: string;
icon2Badge?: string;
action1?: string;
action2?: string;
}

export class AppBar extends React.Component<Props> {
// Set default properties
static defaultProps = {
width: 300,
height: 56,
leftIcon: 'menu',
title: 'Material-UI',
action1: 'Login',
action2: '',
icon1: 'notifications',
icon1Badge: '8',
icon2: 'account_circle',
icon2Badge: '',
};

// Items shown in property panel
static propertyControls: PropertyControls = {
leftIcon: { type: ControlType.String, title: 'Left icon' },
title: { type: ControlType.String, title: 'Title' },
action1: { type: ControlType.String, title: 'Action 1' },
action2: {
type: ControlType.String,
title: 'Action 2',
hidden(props) {
return props.action1 === '' && props.action2 !== '';
},
},
icon1: { type: ControlType.String, title: 'Icon 1' },
icon1Badge: { type: ControlType.String, title: 'Icon 1 badge' },
icon2: {
type: ControlType.String,
title: 'Icon 2',
hidden(props) {
return props.icon1 === '' && props.icon2 !== '';
},
},
icon2Badge: { type: ControlType.String, title: 'Icon 2 badge' },
};

render() {
const { action1, action2, icon1, icon1Badge, icon2, icon2Badge, leftIcon, title } = this.props;
return (
<div style={{ flexGrow: 1 }}>
<MuiAppBar position="static">
<Toolbar>
{leftIcon && (
<IconButton
icon={leftIcon}
// tslint:disable-next-line: ban-ts-ignore
// @ts-ignore
style={{ marginLeft: -12, marginRight: 20 }}
color="inherit"
/>
)}
<Typography variant="h6" color="inherit" style={{ flexGrow: 1 }}>
{title}
</Typography>
{action1 && <Button color="inherit">{action1}</Button>}
{action2 && <Button color="inherit">{action2}</Button>}
{icon1 && (
<IconButton
icon={icon1}
badgeColor="secondary"
badgeContent={icon1Badge}
// tslint:disable-next-line: ban-ts-ignore
// @ts-ignore
style={{ marginRight: 8 }}
color="inherit"
/>
)}
{icon2 && (
<IconButton
icon={icon2}
badgeContent={icon2Badge}
// tslint:disable-next-line: ban-ts-ignore
// @ts-ignore
style={{ marginRight: 8 }}
color="inherit"
/>
)}
</Toolbar>
</MuiAppBar>
</div>
);
}
}
85 changes: 85 additions & 0 deletions framer/Material-UI.framerfx/code/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import * as React from 'react';
import { addPropertyControls, ControlType } from 'framer';
// tslint:disable-next-line: ban-ts-ignore
// @ts-ignore
import MuiAvatar from '@material-ui/core/Avatar';
import { Icon } from './Icon';

interface Props {
backgroundColor?: string;
textColor?: string;
icon?: string;
imageFile?: string;
imageUrl?: string;
label?: string;
width?: number;
height?: number;
}

const defaultProps: Props = {
backgroundColor: '#4154af',
textColor: undefined,
icon: 'face',
imageFile: '',
imageUrl: 'https://i.pravatar.cc/300',
label: 'MB',
width: 40,
height: 40,
};

export const Avatar: React.SFC<Props> = (props: Props) => {
const {
backgroundColor,
height,
icon,
imageFile,
imageUrl,
label,
textColor,
width,
...other
} = props;

return imageFile || imageUrl ? (
<MuiAvatar src={imageFile || imageUrl} style={{ height, width }} {...other} />
) : (
<MuiAvatar style={{ color: textColor, backgroundColor, height, width }} {...other}>
{icon === '' ? label : <Icon icon={icon} />}
</MuiAvatar>
);
};

Avatar.defaultProps = defaultProps;

addPropertyControls(Avatar, {
backgroundColor: {
type: ControlType.Color,
title: 'Background color',
},
textColor: {
type: ControlType.Color,
title: 'Text color',
},
icon: {
type: ControlType.String,
title: 'Icon',
},
imageFile: {
type: ControlType.Image,
title: 'Image File',
hidden: function hidden(props) {
return props.primaryAction && props.primaryAction !== 'avatar';
},
},
imageUrl: {
type: ControlType.String,
title: 'Image URL',
hidden: function hidden(props) {
return props.imageFile !== '' || (props.primaryAction && props.primaryAction !== 'avatar');
},
},
label: {
type: ControlType.String,
title: 'Label',
},
});
Loading

0 comments on commit 6f7318c

Please sign in to comment.