Skip to content

Commit

Permalink
feat: Add Toggle support css-in-js
Browse files Browse the repository at this point in the history
  • Loading branch information
myxvisual committed Aug 8, 2017
1 parent 07ffc39 commit d501b60
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/Theme/getBaseCSSText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ body {
.${themeClassName} input, .${themeClassName} textarea {
box-shadow: none;
border-radius: none;
}`;
}
`;

export default getBaseCSS;
36 changes: 19 additions & 17 deletions src/Toggle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class Toggle extends React.Component<ToggleProps, ToggleState> {
render() {
const {
style,
className,
defaultToggled,
onToggle,
label,
Expand All @@ -73,31 +74,25 @@ export class Toggle extends React.Component<ToggleProps, ToggleState> {
} = this.props;
const { currToggled } = this.state;
const { theme } = this.context;
const styles = getStyles(this);
const styles = theme.prepareStyles({
styles: getStyles(this),
className: "toggle"
});

return (
<div
{...attributes}
style={theme.prefixStyle({
display: "inline-block",
verticalAlign: "middle",
cursor: "default",
...style
})}
>
style={styles.root.style}
className={theme.classNames(styles.root.className, className)}
>
<div
style={styles.root}
{...styles.wrapper}
onClick={this.toggleToggle}
>
<div
style={theme.prefixStyle({
...styles.button,
...styles.button
})}
/>
<div {...styles.button} />
</div>
{label && (
<span style={styles.label}>
<span {...styles.label}>
{label}
</span>
)}
Expand All @@ -108,15 +103,22 @@ export class Toggle extends React.Component<ToggleProps, ToggleState> {

function getStyles(toggle: Toggle): {
root?: React.CSSProperties;
wrapper?: React.CSSProperties;
button?: React.CSSProperties;
label?: React.CSSProperties;
} {
const { size, background } = toggle.props;
const { size, background, style } = toggle.props;
const { theme } = toggle.context;
const { currToggled } = toggle.state;

return {
root: theme.prefixStyle({
display: "inline-block",
verticalAlign: "middle",
cursor: "default",
...style
}),
wrapper: theme.prefixStyle({
userSelect: "none",
position: "relative",
display: "inline-block",
Expand Down
2 changes: 1 addition & 1 deletion src/Tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ export class Tooltip extends React.Component<TooltipProps, TooltipState> {
onMouseLeave={this.unShowTooltip}
>
<span
{...attributes}
ref={tooltipElm => this.tooltipElm = tooltipElm}
{...attributes}
{...theme.prepareStyle({
className: "tooltip",
style: this.getTooltipStyle(),
Expand Down
11 changes: 10 additions & 1 deletion src/TreeView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,21 @@ export class TreeView extends React.Component<TreeViewProps, TreeViewState> {
background,
headerIcon,
itemIcon,
className,
style,
...attributes
} = this.props;
const styles = getStyles(this);

return (
<div {...attributes} style={styles.root}>
<div
{...attributes}
{...this.context.theme.prepareStyle({
style: styles.root,
className: "tree-view",
extendsClassName: className
})}
>
{listSource ? this.renderTree() : null}
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/styles/getTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default function getTheme(themeConfig?: ThemeConfig): ReactUWP.ThemeType
}
},
classNames(...classNames) {
return classNames.reduce((prev, curr) => (prev || "") + curr ? ` ${curr}` : "");
return classNames.reduce((prev, curr) => (prev || "") + (curr ? ` ${curr}` : ""));
},

toasts: [],
Expand Down

0 comments on commit d501b60

Please sign in to comment.