Skip to content

Commit

Permalink
feat: improved icon usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftwork committed Jan 23, 2020
1 parent 65f47e1 commit 7a3c2aa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
11 changes: 3 additions & 8 deletions packages/ui-core/src/styles/colors.stories.tsx
@@ -1,5 +1,6 @@
import React from 'react';
import { base } from '../../postcss.variables.js';
import { Icon } from '@trutoo/ui-icons';

export default {
title: 'Colors',
Expand All @@ -12,14 +13,8 @@ export const basic = () => (
.map(key => (
<figure key={key} className="tu-elevation-1" style={{ padding: 24 }}>
<div style={{ height: 128, padding: 12, background: `var(${key})` }}>
<svg style={{ width: 32, height: 32, fill: 'black' }}>
<use xlinkHref="#icon-ghost" />
</svg>
<svg style={{ width: 32, height: 32, fill: 'white' }}>
<use xlinkHref="#icon-ghost" />
</svg>
<span style={{ width: 32, height: 32, color: 'black' }}></span>
<span style={{ width: 32, height: 32, color: 'white' }}></span>
<Icon id="ghost" size={32} color="black" />
<Icon id="ghost" size={32} color="white" />
</div>
<figcaption style={{ paddingTop: 24 }}>{key}</figcaption>
</figure>
Expand Down
31 changes: 22 additions & 9 deletions packages/ui-datepicker/src/Datepicker.tsx
@@ -1,4 +1,5 @@
import React, { Component, MouseEvent, KeyboardEvent, createRef } from 'react';
import { Icon } from '@trutoo/ui-icons';
import { Validator, ValidationExpression, Grid } from '@trutoo/ui-core';
import scrollIntoView from 'scroll-into-view-if-needed';

Expand Down Expand Up @@ -344,6 +345,26 @@ export default class Datepicker extends Component<Props, State> {
// RENDER
//------------------------------------------------------------------------------------

renderHelper() {
if (this.props.disabled) {
return <Icon id="calendar" className="tu-datepicker--helper no-events" />;
}

if (this.props.value !== null && this.props.value !== undefined && this.props.value.date) {
return (
<Icon
id="calendar-clear"
className="tu-datepicker--helper"
tabIndex={-1}
title={this.props.clearText || 'Clear'}
onClick={this.onClear}
/>
);
}

return <Icon id="calendar" className="tu-datepicker--helper no-events" />;
}

render() {
// Reset date refs on render
this.dateRefs = {};
Expand Down Expand Up @@ -387,15 +408,7 @@ export default class Datepicker extends Component<Props, State> {
{...this.props.inputProps}
/>

{this.props.disabled || !this.state.focused ? (
<svg className="tu-datepicker--helper no-events">
<use xlinkHref="#icon-calendar" />
</svg>
) : (
<svg className="tu-datepicker--helper" tabIndex={-1} onMouseDown={this.onClear}>
<use xlinkHref="#icon-calendar-clear" />
</svg>
)}
{this.renderHelper()}

{this.state.dates && (
<Grid className="tu-datepicker--select" columns={7} id={`${this.state.id}-results`}>
Expand Down
11 changes: 9 additions & 2 deletions packages/ui-typeahead/src/Typeahead.tsx
Expand Up @@ -324,11 +324,16 @@ export default class Typeahead<T extends TypeaheadResult = TypeaheadResult> exte
);
}

if (this.props.disabled || !this.state.focused) {
if (this.props.disabled) {
return <Icon id="arrows-vertical" className="tu-typeahead--helper no-events" />;
}

if (!this.props.readonly && this.hasValueOrFocus()) {
if (
!this.props.readonly &&
this.props.value !== null &&
this.props.value !== undefined &&
this.props.value.view !== ''
) {
return (
<Icon
id="close"
Expand All @@ -339,6 +344,8 @@ export default class Typeahead<T extends TypeaheadResult = TypeaheadResult> exte
/>
);
}

return <Icon id="arrows-vertical" className="tu-typeahead--helper no-events" />;
}

render() {
Expand Down

0 comments on commit 7a3c2aa

Please sign in to comment.