Skip to content

Commit

Permalink
Button timer (uber#5160)
Browse files Browse the repository at this point in the history
* feat(button-timer): sketch out basic component

* chore(button-timed): add index.js.flow

* fix(button-timed): fix undefined overrides

* fix(button-timed): button fill speed

* chore(button-timed): handle button state after click

* chore(button-timed): add docs

* chore(button-timed): improve post-countdown styles

* chore(button-timed): add e2e tests

* chore(button-timed): extract out timeRemaining state management

* chore(button-timed): fix overrides implementation

* feat(button-timed): implement pause function

* chore(button-timed): extract out use-paused

* chore(button-timed): extract out utils

* chore(button-timed): remove stateless version of component

* chore(button-timed): smooth out animation

* chore(button-timed): update docs

* chore(button-timed): fix merged overrides

* test(vrt): update visual snapshots for 39e11cf [skip ci] (uber#5161)

Co-authored-by: UberOpenSourceBot <[email protected]>

* chore(button-timed): move // @flow to top of file

* chore(button-timed): fix flow types

* chore(button-timed): fix test issue

* chore(button-timed): add more unit tests

* chore(button-timed): use jest fake timers

* chore(button-timed): fix syntax for jest fake timers

* chore(button-timed): comment out failing unit test

* chore(button-timed): delete failing unit tests file

* chore(button-timed): add integration test

* test(vrt): update visual snapshots for d0eb440 [skip ci] (uber#5190)

Co-authored-by: UberOpenSourceBot <[email protected]>

Co-authored-by: UberOpenSourceBot <[email protected]>
Co-authored-by: UberOpenSourceBot <[email protected]>
  • Loading branch information
3 people authored Oct 6, 2022
1 parent 6a4890f commit 71655c0
Show file tree
Hide file tree
Showing 24 changed files with 772 additions and 36 deletions.
84 changes: 48 additions & 36 deletions documentation-site/cheat-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,13 @@ const outlines = [
{ name: 'StateReducer', lineStart: 77, children: [] },
],
},
{
file: 'src/button-timed/types.ts',
definitions: [
{ name: 'ButtonTimedOverrides', lineStart: 10, children: [] },
{ name: 'ButtonTimedProps', lineStart: 14, children: [] },
],
},
{
file: 'src/card/types.ts',
definitions: [
Expand Down Expand Up @@ -863,38 +870,47 @@ const outlines = [
{ name: 'renderButton', lineStart: 87 },
],
},
{ name: 'ImperativeMethods', lineStart: 90, children: [{ name: 'getRows', lineStart: 91 }] },
{ name: 'ControlRef', lineStart: 94, children: [{ name: 'current', lineStart: 95 }] },
{
name: 'ImperativeMethods',
lineStart: 90,
children: [
{ name: 'getRows', lineStart: 91 },
{ name: 'clearSelection', lineStart: 92 },
],
},
{ name: 'ControlRef', lineStart: 95, children: [{ name: 'current', lineStart: 96 }] },
{
name: 'StatefulDataTableProps',
lineStart: 98,
lineStart: 99,
children: [
{ name: 'batchActions', lineStart: 99 },
{ name: 'columns', lineStart: 100 },
{ name: 'emptyMessage', lineStart: 101 },
{ name: 'filterable', lineStart: 102 },
{ name: 'initialFilters', lineStart: 103 },
{ name: 'initialSelectedRowIds', lineStart: 109 },
{ name: 'initialSortIndex', lineStart: 110 },
{ name: 'initialSortDirection', lineStart: 111 },
{ name: 'loading', lineStart: 112 },
{ name: 'loadingMessage', lineStart: 113 },
{ name: 'onFilterAdd', lineStart: 114 },
{ name: 'onFilterRemove', lineStart: 120 },
{ name: 'onIncludedRowsChange', lineStart: 121 },
{ name: 'onRowHighlightChange', lineStart: 122 },
{ name: 'onSelectionChange', lineStart: 123 },
{ name: 'resizableColumnWidths', lineStart: 124 },
{ name: 'rows', lineStart: 125 },
{ name: 'rowActions', lineStart: 126 },
{ name: 'rowHeight', lineStart: 127 },
{ name: 'rowHighlightIndex', lineStart: 128 },
{ name: 'searchable', lineStart: 129 },
{ name: 'controlRef', lineStart: 130 },
],
},
{ name: 'DataTableProps', lineStart: 133, children: [] },
{ name: 'StatefulContainerProps', lineStart: 157, children: [] },
{ name: 'batchActions', lineStart: 100 },
{ name: 'columns', lineStart: 101 },
{ name: 'emptyMessage', lineStart: 102 },
{ name: 'filterable', lineStart: 103 },
{ name: 'initialFilters', lineStart: 104 },
{ name: 'initialSelectedRowIds', lineStart: 110 },
{ name: 'initialSortIndex', lineStart: 111 },
{ name: 'initialSortDirection', lineStart: 112 },
{ name: 'loading', lineStart: 113 },
{ name: 'loadingMessage', lineStart: 114 },
{ name: 'onFilterAdd', lineStart: 115 },
{ name: 'onFilterRemove', lineStart: 121 },
{ name: 'onIncludedRowsChange', lineStart: 122 },
{ name: 'onRowHighlightChange', lineStart: 123 },
{ name: 'onSelectionChange', lineStart: 124 },
{ name: 'onSort', lineStart: 125 },
{ name: 'onTextQueryChange', lineStart: 126 },
{ name: 'resizableColumnWidths', lineStart: 127 },
{ name: 'rows', lineStart: 128 },
{ name: 'rowActions', lineStart: 129 },
{ name: 'rowHeight', lineStart: 130 },
{ name: 'rowHighlightIndex', lineStart: 131 },
{ name: 'searchable', lineStart: 132 },
{ name: 'controlRef', lineStart: 133 },
],
},
{ name: 'DataTableProps', lineStart: 136, children: [] },
{ name: 'StatefulContainerProps', lineStart: 160, children: [] },
],
},
{
Expand Down Expand Up @@ -1398,14 +1414,10 @@ const outlines = [
definitions: [
{
name: 'HeaderNavigationOverrides',
lineStart: 9,
children: [{ name: 'Root', lineStart: 10 }],
},
{
name: 'HeaderNavigationProps',
lineStart: 13,
children: [{ name: 'overrides', lineStart: 14 }],
lineStart: 10,
children: [{ name: 'Root', lineStart: 11 }],
},
{ name: 'HeaderNavigationProps', lineStart: 14, children: [] },
],
},
{
Expand Down
116 changes: 116 additions & 0 deletions documentation-site/components/yard/config/button-timed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
Copyright (c) Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import { ButtonTimed } from 'baseui/button-timed';
import { PropTypes } from 'react-view';
import type { TConfig } from '../types';

const ButtonTimedConfig: TConfig = {
componentName: 'ButtonTimed',
imports: {
'baseui/button-timed': {
named: ['ButtonTimed'],
},
},
scope: {
ButtonTimed,
},
theme: [
'buttonPrimaryFill',
'buttonPrimaryText',
'buttonPrimaryHover',
'buttonPrimaryActive',
'buttonSecondaryFill',
'buttonSecondaryText',
'buttonSecondaryHover',
'buttonSecondaryActive',
'buttonTertiaryFill',
'buttonTertiaryText',
'buttonTertiaryHover',
'buttonTertiaryActive',
'buttonTertiarySelectedFill',
'buttonTertiarySelectedText',
'buttonMinimalFill',
'buttonMinimalText',
'buttonMinimalHover',
'buttonMinimalActive',
'buttonDisabledFill',
'buttonDisabledText',
],
props: {
children: {
value: 'Label',
type: PropTypes.ReactNode,
description: `Visible label.`,
},
onClick: {
value: '() => alert("click")',
type: PropTypes.Function,
description: `Function called when time runs out or button is clicked.`,
},
initialTime: {
value: 15,
type: PropTypes.Number,
description: `Number of seconds before onClick is automatically invoked`,
},
startEnhancer: {
value: undefined,
placeholder: '() => <span>🦊</span>',
type: PropTypes.Function,
description: `A component rendered at the start of the button.`,
hidden: true,
},
endEnhancer: {
value: undefined,
placeholder: '<i>world!</i>',
type: PropTypes.Function,
description: `A component rendered at the end of the button.`,
hidden: true,
},
disabled: {
value: false,
type: PropTypes.Boolean,
description: 'Indicates that the button is disabled',
hidden: true,
},
colors: {
value: undefined,
defaultValue: '{backgroundColor: "#03703c", color: "white"}',
type: PropTypes.Object,
description: 'Lets you customize the background and text color.',
hidden: true,
},
isLoading: {
value: false,
type: PropTypes.Boolean,
description: 'Show loading button style and spinner.',
hidden: true,
},
isSelected: {
value: false,
type: PropTypes.Boolean,
description: 'Indicates that the button is selected.',
hidden: true,
},
overrides: {
value: undefined,
type: PropTypes.Custom,
description: 'Lets you customize all aspects of the component.',
custom: {
names: [
'BaseButtonTimed',
'TimerContainer',
'EndEnhancer',
'LoadingSpinner',
'LoadingSpinnerContainer',
'StartEnhancer',
],
},
},
},
};

export default ButtonTimedConfig;
91 changes: 91 additions & 0 deletions documentation-site/examples/button-timed/paused.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// @flow
/*
Copyright (c) Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import * as React from 'react';

import {ButtonTimed} from 'baseui/button-timed';
import {Button, KIND} from 'baseui/button';

export default function Example() {
const [finished1, setFinished1] = React.useState(false);
const [finished2, setFinished2] = React.useState(false);
const [finished3, setFinished3] = React.useState(false);
const [finished4, setFinished4] = React.useState(false);

const [paused, setPaused] = React.useState(true);

return (
<div>
<Button
kind={KIND.secondary}
onClick={() => setPaused(!paused)}
>
{paused ? 'Run' : 'Pause'}
</Button>

<div>
<ButtonTimed
onClick={() => setFinished1(true)}
initialTime={10}
paused={paused}
>
Countdown
</ButtonTimed>
{finished1 && (
<span style={{marginLeft: '20px', color: 'red'}}>
Time!
</span>
)}
</div>

<div>
<ButtonTimed
onClick={() => setFinished2(true)}
initialTime={18}
paused={paused}
>
Countdown
</ButtonTimed>
{finished2 && (
<span style={{marginLeft: '20px', color: 'blue'}}>
Time!
</span>
)}
</div>

<div>
<ButtonTimed
onClick={() => setFinished3(true)}
initialTime={35}
paused={paused}
>
Countdown
</ButtonTimed>
{finished3 && (
<span style={{marginLeft: '20px', color: 'gold'}}>
Time!
</span>
)}
</div>

<div>
<ButtonTimed
onClick={() => setFinished4(true)}
initialTime={60}
paused={paused}
>
Countdown
</ButtonTimed>
{finished4 && (
<span style={{marginLeft: '20px', color: 'green'}}>
Time!
</span>
)}
</div>
</div>
);
}
Loading

0 comments on commit 71655c0

Please sign in to comment.