Skip to content

Commit

Permalink
feat: Add AutoSuggestBox 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 f2b9126 commit 44a33fb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
10 changes: 6 additions & 4 deletions src/AppBarButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ export class AppBarButtonButton extends React.Component<AppBarButtonButtonProps>
style: styles.root.style,
className: theme.classNames(className, styles.root.className)
};
const normalRender = (
<div {...rootProps}>

const getNormalRender = (props?: any) => (
<div {...props}>
<Icon {...styles.icon}>
{icon}
</Icon>
Expand All @@ -68,11 +69,12 @@ export class AppBarButtonButton extends React.Component<AppBarButtonButtonProps>
</p>}
</div>
);

return theme.useInlineStyle ? (
<PseudoClassesComponent {...rootProps}>
{normalRender}
{getNormalRender()}
</PseudoClassesComponent>
) : normalRender;
) : getNormalRender(rootProps);
}
}

Expand Down
42 changes: 24 additions & 18 deletions src/AutoSuggestBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,31 @@ export class AutoSuggestBox extends React.Component<AutoSuggestBoxProps, AutoSug
listSource, // tslint:disable-line:no-unused-variable
iconSize, // tslint:disable-line:no-unused-variable
children, // tslint:disable-line:no-unused-variable
className,
background,
...attributes
} = this.props;
const {
typing,
focusListSourceIndex
} = this.state;
const styles = getStyles(this);
const { theme } = this.context;

const styles = theme.prepareStyles({
styles: getStyles(this),
className: "autosuggest-box"
});

const rootProps = {
...attributes,
style: styles.root.style,
className: theme.classNames(className, styles.root.className)
};

return (
<TextBox
{...attributes}
{...rootProps}
ref={textBox => this.textBox = textBox}
style={styles.root}
onClick={this.showListSource}
onKeyDown={this.handleInputKeyDown}
rightNode={(
Expand All @@ -236,7 +247,7 @@ export class AutoSuggestBox extends React.Component<AutoSuggestBoxProps, AutoSug
{listSource && listSource.length > 0 && (
<ListView
ref={listView => this.listView = listView}
style={styles.listView}
{...styles.listView}
listSource={listSource.map((itemNode, index) => ({
itemNode,
focus: index === focusListSourceIndex
Expand All @@ -255,10 +266,7 @@ export class AutoSuggestBox extends React.Component<AutoSuggestBoxProps, AutoSug
function getStyles(autoSuggestBox: AutoSuggestBox): {
root?: React.CSSProperties;
listView?: React.CSSProperties;
iconsStyles?: {
style?: React.CSSProperties;
hoverStyle?: React.CSSProperties;
}
iconsStyles?: React.CSSProperties;
} {
const { context, props: {
style,
Expand Down Expand Up @@ -286,16 +294,14 @@ function getStyles(autoSuggestBox: AutoSuggestBox): {
transition: "all .25s"
}),
iconsStyles: {
style: {
position: "absolute",
top: 0,
right: 0,
cursor: "pointer",
height: iconSize,
width: iconSize,
color: "#a9a9a9"
},
hoverStyle: {
position: "absolute",
top: 0,
right: 0,
cursor: "pointer",
height: iconSize,
width: iconSize,
color: "#a9a9a9",
"&:hover": {
color: theme.accent
}
}
Expand Down

0 comments on commit 44a33fb

Please sign in to comment.