Skip to content

Commit

Permalink
Remove delayTime from API and set autoClose boolean and number | F…
Browse files Browse the repository at this point in the history
…ixes liferay#910

`autoClose` to true follows the default values and when number follows the values passed by the API.

Default times:
Stripe: 5s
Toast: 8s
  • Loading branch information
matuzalemsteles committed May 22, 2018
1 parent 77e9d07 commit 8402e1e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
28 changes: 11 additions & 17 deletions packages/clay-alert/src/ClayAlertBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Component from 'metal-component';
import defineWebComponent from 'metal-web-component';
import Soy from 'metal-soy';
import {Config} from 'metal-state';
import {isServerSide} from 'metal';
import {isServerSide, isNumber} from 'metal';

import templates from './ClayAlertBase.soy.js';

Expand Down Expand Up @@ -118,11 +118,10 @@ class ClayAlertBase extends Component {
this.autoClose &&
(this.type === 'stripe' || this.type === 'toast')
) {
if (this.delayTime) {
this._delayTime = this.delayTime * 1000;
if (isNumber(this.autoClose)) {
this._delayTime = this.autoClose * 1000;
} else {
this._delayTime =
(this.element.querySelector('a') ? 10 : 5) * 1000;
this._delayTime = (this.type === 'toast' ? 8 : 5) * 1000;
}

this._resumeTimeout();
Expand Down Expand Up @@ -156,13 +155,17 @@ ClayAlertBase.STATE = {
.value(true),

/**
* Flag to indicate if alert should be automatically closed.
* Flag to `true` to indicate whether the alert should be closed
* automatically with the default time.
* @default false
* @instance
* @memberof ClayAlertBase
* @type {?bool}
* @type {?(bool|number)}
*/
autoClose: Config.bool().value(false),
autoClose: Config.oneOfType([
Config.bool().value(false),
Config.number()
]),

/**
* Flag to indicate if the alert is closeable.
Expand All @@ -182,15 +185,6 @@ ClayAlertBase.STATE = {
*/
destroyOnHide: Config.bool().value(false),

/**
* Set time per second for alert autoclose.
* @default undefineds
* @instance
* @memberof ClayAlertBase
* @type {?number}
*/
delayTime: Config.number(),

/**
* CSS classes to be applied to the element.
* @default undefined
Expand Down
10 changes: 7 additions & 3 deletions packages/clay-alert/src/ClayStripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ class ClayStripe extends Component {
*/
ClayStripe.STATE = {
/**
* Flag to indicate if alert should be automatically closed.
* Flag to `true` to indicate whether the alert should be closed
* automatically with the default time.
* @default false
* @instance
* @memberof ClayStripe
* @type {?bool}
* @type {?(bool|number)}
*/
autoClose: Config.bool().value(false),
autoClose: Config.oneOfType([
Config.bool().value(false),
Config.number()
]),

/**
* Flag to indicate if the alert should be destroyen when close.
Expand Down
2 changes: 1 addition & 1 deletion packages/clay-alert/src/ClayStripe.soy
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{@param spritemap: string}
{@param title: string}
{@param? _handleHide: any}
{@param? autoClose: bool}
{@param? autoClose: bool|number}
{@param? elementClasses: string}
{@param? id: string}
{@param? style: string}
Expand Down
10 changes: 7 additions & 3 deletions packages/clay-alert/src/ClayToast.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ class ClayToast extends Component {
*/
ClayToast.STATE = {
/**
* Flag to indicate if alert should be automatically closed.
* Flag to `true` to indicate whether the alert should be closed
* automatically with the default time.
* @default false
* @instance
* @memberof ClayToast
* @type {?bool}
* @type {?(bool|number)}
*/
autoClose: Config.bool().value(false),
autoClose: Config.oneOfType([
Config.bool().value(false),
Config.number()
]),

/**
* Flag to indicate if the alert should be destroyen when close.
Expand Down
3 changes: 1 addition & 2 deletions packages/clay-alert/src/ClayToast.soy
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
{@param spritemap: string}
{@param title: string}
{@param? _handleHide: any}
{@param? autoClose: bool}
{@param? autoClose: bool|number}
{@param? elementClasses: string}
{@param? id: string}
{@param? style: string}

{call ClayAlertBase.render}
{param autoClose: $autoClose /}
{param closeable: true /}
{param delayTime: 8 /}
{param elementClasses: $elementClasses /}
{param events: ['hide': $_handleHide ] /}
{param id: $id /}
Expand Down

0 comments on commit 8402e1e

Please sign in to comment.