Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 feat(stepper): add custom color for stepper #673

Merged
merged 6 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/yoga/src/Stepper/Stepper.theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ const Stepper = ({ colors, spacing, fontSizes, fontWeights, radii }) => ({
backgroundColor: {
active: colors.primary,
inactive: colors.elements.backgroundAndDisabled,
secondary: colors.medium,
},
},
dot: {
radius: radii.circle,
backgroundColor: {
active: colors.primary,
inactive: colors.elements.backgroundAndDisabled,
secondary: colors.medium,
},
},
label: {
Expand All @@ -24,6 +26,7 @@ const Stepper = ({ colors, spacing, fontSizes, fontWeights, radii }) => ({
color: {
active: colors.primary,
inactive: colors.elements.selectionAndIcons,
secondary: colors.medium,
},
},
});
Expand Down
81 changes: 46 additions & 35 deletions packages/yoga/src/Stepper/native/Dots.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { arrayOf, bool, number, string } from 'prop-types';
import React from 'react';
import { number, arrayOf, string } from 'prop-types';
import styled from 'styled-components';
import styled, { css } from 'styled-components';

import activeDot from '../activeDot';
import Text from '../../Text';
import activeDot from '../activeDot';

const Wrapper = styled.View`
flex-direction: row;
Expand All @@ -17,67 +17,78 @@ const DotWrapper = styled.View`
const Dot = styled.View(
({
active,
secondary,
theme: {
yoga: {
components: { stepper },
},
},
}) => `
width: 15px;
height: 15px;
}) => {
const state = secondary ? 'secondary' : 'active';

margin-top: -6px;
return css`
width: 15px;
height: 15px;
margin-top: -6px;
border-radius: ${stepper.dot.radius}px;
background-color: ${
active
? stepper.dot.backgroundColor.active
: stepper.dot.backgroundColor.inactive
};
`,
border-radius: ${stepper.dot.radius}px;
background-color: ${active
? stepper.dot.backgroundColor[state]
: stepper.dot.backgroundColor.inactive};
`;
},
);

const Label = styled(Text.Bold)(
({
active,
secondary,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Replace ···· with ··

Suggested change
secondary,
secondary,

theme: {
yoga: {
components: { stepper },
},
},
}) => `
width: 95px;
margin-top: 10px;
margin-left: -40px;
}) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Delete ··

Suggested change
}) => {
}) => {

const state = secondary ? 'secondary' : 'active';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Delete ··

Suggested change
const state = secondary ? 'secondary' : 'active';
const state = secondary ? 'secondary' : 'active';


color: ${
active ? stepper.label.color.active : stepper.label.color.inactive
};
font-size: ${stepper.label.font.size}px;
text-align: center;
`,
return css`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Delete ··

Suggested change
return css`
return css`

width: 95px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Delete ··

Suggested change
width: 95px;
width: 95px;

margin-top: 10px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Delete ··

Suggested change
margin-top: 10px;
margin-top: 10px;

margin-left: -40px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Delete ··

Suggested change
margin-left: -40px;
margin-left: -40px;

color: ${active
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Delete ··

Suggested change
color: ${active
color: ${active

? stepper.label.color[state]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Delete ··

Suggested change
? stepper.label.color[state]
? stepper.label.color[state]

: stepper.label.color.inactive};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Replace ········ with ······

Suggested change
: stepper.label.color.inactive};
: stepper.label.color.inactive};

font-size: ${stepper.label.font.size}px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Delete ··

Suggested change
font-size: ${stepper.label.font.size}px;
font-size: ${stepper.label.font.size}px;

text-align: center;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Delete ··

Suggested change
text-align: center;
text-align: center;

`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Replace ···· with ··

Suggested change
`;
`;

},
);

const Dots = ({ activeStep, labels }) => (
<Wrapper>
{labels.map((label, index) => (
<DotWrapper key={label}>
<Dot active={activeDot(index, activeStep)} />
<Label active={activeDot(index, activeStep)}>{label}</Label>
</DotWrapper>
))}
</Wrapper>
);
function Dots({ activeStep, labels, secondary }) {
return (
<Wrapper>
{labels.map((label, index) => (
<DotWrapper key={label}>
<Dot active={activeDot(index, activeStep)} secondary={secondary} />
<Label active={activeDot(index, activeStep)} secondary={secondary}>
{label}
</Label>
</DotWrapper>
))}
</Wrapper>
);
}

Dots.propTypes = {
activeStep: number,
labels: arrayOf(string),
secondary: bool,
};

Dots.defaultProps = {
activeStep: 0,
labels: [],
secondary: false,
};

export default Dots;
28 changes: 20 additions & 8 deletions packages/yoga/src/Stepper/native/Line.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { number } from 'prop-types';
import { bool, number } from 'prop-types';
import styled from 'styled-components';

const Wrapper = styled.View`
Expand Down Expand Up @@ -27,6 +27,7 @@ const InactiveLine = styled.View(
const ActiveLine = styled.View(
({
width,
secondary,
theme: {
yoga: {
components: { stepper },
Expand All @@ -36,27 +37,38 @@ const ActiveLine = styled.View(
position: absolute;
top: 0;
background-color: ${stepper.line.backgroundColor.active};
background-color: ${
secondary
? stepper.line.backgroundColor.secondary
: stepper.line.backgroundColor.active
};
width: ${width}%;
height: 4px;
`,
);

const Line = ({ activeStep, totalSteps }) => (
<Wrapper>
<InactiveLine />
<ActiveLine width={activeStep <= 0 ? 0 : (activeStep / totalSteps) * 100} />
</Wrapper>
);
function Line({ activeStep, totalSteps, secondary }) {
return (
<Wrapper>
<InactiveLine />
<ActiveLine
width={activeStep <= 0 ? 0 : (activeStep / totalSteps) * 100}
secondary={secondary}
/>
</Wrapper>
);
}

Line.propTypes = {
activeStep: number,
totalSteps: number,
secondary: bool,
};

Line.defaultProps = {
activeStep: 0,
totalSteps: 0,
secondary: false,
};

export default Line;
38 changes: 23 additions & 15 deletions packages/yoga/src/Stepper/native/Stepper.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import styled from 'styled-components';

import { bool } from 'prop-types';
import { limitChildren, typeOf } from '../../shared';
import Line from './Line';
import Dots from './Dots';
Expand All @@ -25,21 +26,25 @@ const LineWrapper = styled.View(

/** Stepper is responsible for the logic that drives a stepped workflow, it
provides a wizard-like workflow by dividing content into logical steps. */
const Stepper = ({ children, activeStep, ...rest }) => (
<Wrapper {...rest}>
<LineWrapper>
<Line
activeStep={activeStep}
totalSteps={React.Children.count(children) - 1}
/>
<Dots
activeStep={activeStep}
labels={React.Children.map(children, child => child.props.label)}
/>
</LineWrapper>
{React.Children.toArray(children)[activeStep]}
</Wrapper>
);
function Stepper({ children, activeStep, secondary, ...rest }) {
return (
<Wrapper {...rest}>
<LineWrapper>
<Line
activeStep={activeStep}
totalSteps={React.Children.count(children) - 1}
secondary={secondary}
/>
<Dots
activeStep={activeStep}
labels={React.Children.map(children, child => child.props.label)}
secondary={secondary}
/>
</LineWrapper>
{React.Children.toArray(children)[activeStep]}
</Wrapper>
);
}

Stepper.displayName = 'Stepper';

Expand All @@ -49,11 +54,14 @@ Stepper.propTypes = {
/** Controls the active step, it receive the index value for showing some
* step. Starting from 0. */
activeStep: limitChildren,
/** Must be a color from yoga colors. */
Falkaniere marked this conversation as resolved.
Show resolved Hide resolved
secondary: bool,
};

Stepper.defaultProps = {
children: undefined,
activeStep: 0,
secondary: false,
};

export default Stepper;
20 changes: 20 additions & 0 deletions packages/yoga/src/Stepper/native/Stepper.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ describe('<Stepper />', () => {
expect(toJSON(container)).toMatchSnapshot();
});

it('should match snapshot with first step active and secondary color', () => {
const { container, toJSON } = render(
<ThemeProvider>
<Stepper activeStep={0} secondary>
<Stepper.Step label="step one">
<Text>step one content</Text>
</Stepper.Step>
<Stepper.Step label="step two">
<Text>step two content</Text>
</Stepper.Step>
<Stepper.Step label="step three">
<Text>step three content</Text>
</Stepper.Step>
</Stepper>
</ThemeProvider>,
);

expect(toJSON(container)).toMatchSnapshot();
});

it('should match snapshot with second step active', () => {
const { container, toJSON } = render(
<ThemeProvider>
Expand Down
Loading
Loading