Skip to content

Commit

Permalink
feat(pageHeader): adds stepper component in pageHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
riyalohia committed Sep 4, 2020
1 parent f557012 commit 245bd8d
Show file tree
Hide file tree
Showing 4 changed files with 315 additions and 15 deletions.
21 changes: 8 additions & 13 deletions core/components/molecules/stepper/Stepper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ export interface StepProp {
value?: React.ReactText;
}

export interface CompProps extends BaseProps {
export interface StepperProps extends BaseProps {
/**
* Set the active step (zero based index).
*
* Set to -1 to disable all the steps.
*/
active?: number;
active: number;
/**
* Set the completed steps (zero based index).
*
* **Number of completed steps <= completed index**
*/
completed?: number;
completed: number;
/**
* <pre className="docPage-codeBlock">
* StepProp {
Expand All @@ -47,15 +47,6 @@ export interface CompProps extends BaseProps {
) => void;
}

const defaultProps = {
completed: -1,
active: 0,
};

type DefaultProps = Readonly<typeof defaultProps>;

export type StepperProps = CompProps & DefaultProps;

export const Stepper = (props: StepperProps) => {
const {
steps,
Expand Down Expand Up @@ -109,6 +100,10 @@ export const Stepper = (props: StepperProps) => {
);
};

Stepper.defaultProps = defaultProps;
Stepper.defaultProps = {
completed: -1,
active: 0,
steps: []
};

export default Stepper;
13 changes: 11 additions & 2 deletions core/components/organisms/pageHeader/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export interface PageHeaderProps extends BaseProps {
* `Navigation` component
*/
navigation?: React.ReactNode;
/**
* `Stepper` component
*/
stepper?: React.ReactNode;
/**
* Actions composed of `Button` and meta data
*/
Expand Down Expand Up @@ -53,6 +57,7 @@ export const PageHeader = (props: PageHeaderProps) => {
const {
title,
navigation,
stepper,
actions,
tabs,
breadcrumbs,
Expand All @@ -75,6 +80,10 @@ export const PageHeader = (props: PageHeaderProps) => {
PageHeader: true
});

const renderCenter = () => {
return navigation ? navigation : stepper;
};

return (
<div {...baseProps} className={wrapperClasses}>
{breadcrumbs && breadcrumbs}
Expand All @@ -88,7 +97,7 @@ export const PageHeader = (props: PageHeaderProps) => {
</Column>
<Column size="4" sizeXL="4" sizeM="4">
<div className="PageHeader-navigationWrapper">
{(!breadcrumbs || navigationPosition === 'center') && navigation}
{(!breadcrumbs || navigationPosition === 'center') && renderCenter()}
</div>
</Column>
<Column size="4" sizeXL="4" sizeM="4">
Expand All @@ -103,7 +112,7 @@ export const PageHeader = (props: PageHeaderProps) => {
</div>
)}
{breadcrumbs && navigationPosition === 'bottom' && (
<div className="PageHeader-navigationWrapper">{navigation}</div>)}
<div className="PageHeader-navigationWrapper">{renderCenter()}</div>)}
{tabs && <div>{tabs}</div>}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import * as React from 'react';
import PageHeader from '../..//PageHeader';
import { Stepper, Button, Text } from '@/index';
import { text, boolean } from '@storybook/addon-knobs';

export const withStepper = () => {
const title = text(
'title',
'Page title'
);

const stepperData = [
{
value: 'step_1',
label: 'Step 1',
},
{
value: 'step_2',
label: 'Step 2'
},
{
value: 'step_3',
label: 'Step 3',
}
];

const seperator = boolean('seperator', true);

const [active, setActive] = React.useState(0);
const [completed, setCompleted] = React.useState(-1);

const onChangeHandler = (activeStep: number) => {
setActive(activeStep);
};

const onClickHandler = () => {
if (active > completed) setCompleted(active);
active > completed ? setActive(active + 1) : setActive(completed + 1);
};

const options = {
title,
seperator,
stepper: <Stepper steps={stepperData} onChange={onChangeHandler} active={active} completed={completed} />,
actions: (
<div style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
<span className="mr-4"><Text appearance="subtle">Meta data</Text></span>
<Button appearance="primary" onClick={onClickHandler}>Next</Button>
</div>
)
};

return (
<div className="w-100 p-6" style={{ background: '#f4f4f4' }}>
<PageHeader {...options} />
</div>
);
};

const customCode = `() => {
const title = 'Page title';
const stepperData = [
{
value: 'step_1',
label: 'Step 1',
},
{
value: 'step_2',
label: 'Step 2'
},
{
value: 'step_3',
label: 'Step 3',
}
];
const [active, setActive] = React.useState(0);
const [completed, setCompleted] = React.useState(-1);
const onChangeHandler = (activeStep) => {
setActive(activeStep)
};
const onClickHandler = () => {
if (active > completed) setCompleted(active);
active > completed ? setActive(active + 1) : setActive(completed + 1);
}
const options = {
title,
seperator: true,
stepper: <Stepper steps={stepperData} onChange={onChangeHandler} active={active} completed={completed} />,
actions: (
<div style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
<span className="mr-4"><Text appearance="subtle">Meta data</Text></span>
<Button appearance="primary" onClick={onClickHandler}>Primary</Button>
</div>
)
};
return (
<div className="w-100 p-6" style={{ background: '#f4f4f4' }}>
<PageHeader {...options} />
</div>
);
}`;

export default {
title: 'Organisms|PageHeader/Level 0/Variants',
component: PageHeader,
parameters: {
docs: {
docPage: {
customCode
}
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import * as React from 'react';
import PageHeader from '../../PageHeader';
import { select, text, boolean } from '@storybook/addon-knobs';
import { Stepper, Button, Breadcrumbs, Badge, StatusHint } from '@/index';
import { action } from '@storybook/addon-actions';

export const withStepper = () => {
const navigationPosition = select(
'navigationPosition',
['center', 'bottom'],
'center'
);
const seperator = boolean('seperator', true);
const title = text(
'title',
'Page title'
);

const stepperData = [
{
value: 'step_1',
label: 'Step 1',
},
{
value: 'step_2',
label: 'Step 2'
},
{
value: 'step_3',
label: 'Step 3',
}
];

const breadcrumbData = [
{
label: 'Level 0',
link: '/level0'
},
{
label: 'Level 1',
link: '/level1'
}
];

const [active, setActive] = React.useState(0);
const [completed, setCompleted] = React.useState(-1);

const onChangeHandler = (activeStep: number) => {
setActive(activeStep);
};

const onClickHandler = () => {
if (active > completed) setCompleted(active);
active > completed ? setActive(active + 1) : setActive(completed + 1);
};

const options = {
navigationPosition,
title,
seperator,
stepper: <Stepper steps={stepperData} onChange={onChangeHandler} active={active} completed={completed} />,
actions: (
<div style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
<Button appearance="primary" onClick={onClickHandler}>Next</Button>
</div>
),
breadcrumbs: (
<Breadcrumbs
list={breadcrumbData}
onClick={link => action(`on-click: ${link}`)}
/>
),
badge: (
<Badge appearance="secondary">Badge</Badge>
),
status: (
<StatusHint appearance="alert">Alert</StatusHint>
),
meta: (
<StatusHint appearance="default">Meta Data</StatusHint>
)
};

return (
<div className="w-100 p-6" style={{ background: '#f4f4f4' }}>
<PageHeader {...options} />
</div>
);
};

const customCode = `() => {
const navigationPosition = 'center';
const title = 'Page title';
const stepperData = [
{
value: 'step_1',
label: 'Step 1',
},
{
value: 'step_2',
label: 'Step 2'
},
{
value: 'step_3',
label: 'Step 3',
}
];
const breadcrumbData = [
{
label: 'Level 0',
link: '/level0'
},
{
label: 'Level 1',
link: '/level1'
}
];
const [active, setActive] = React.useState(0);
const [completed, setCompleted] = React.useState(-1);
const onChangeHandler = (activeStep) => {
setActive(activeStep)
};
const onClickHandler = () => {
if (active > completed) setCompleted(active);
active > completed ? setActive(active + 1) : setActive(completed + 1);
};
const options = {
navigationPosition,
title,
seperator: true,
stepper: <Stepper steps={stepperData} onChange={onChangeHandler} active={active} completed={completed} />,
actions: (
<div style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
<Button appearance="primary" onClick={onClickHandler}>Next</Button>
</div>
),
breadcrumbs: (
<Breadcrumbs
list={breadcrumbData}
/>
),
badge: (
<Badge appearance="secondary">Badge</Badge>
),
status: (
<StatusHint appearance="alert">Alert</StatusHint>
),
meta: (
<StatusHint appearance="default">Meta Data</StatusHint>
)
};
return (
<div className="w-100 p-6" style={{ background: '#f4f4f4' }}>
<PageHeader {...options} />
</div>
);
}`;

export default {
title: 'Organisms|PageHeader/Level 1/Variants',
component: PageHeader,
parameters: {
docs: {
docPage: {
customCode
}
}
}
};

0 comments on commit 245bd8d

Please sign in to comment.