Skip to content

Commit

Permalink
feat: create section title component (#5237)
Browse files Browse the repository at this point in the history
Co-authored-by: Wai.Tung <[email protected]>
  • Loading branch information
2 people authored and ovflowd committed May 3, 2023
1 parent 7227b35 commit eaff4f4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
17 changes: 17 additions & 0 deletions components/Common/SectionTitle/__tests__/SectionTitle.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { render, screen } from '@testing-library/react';
import SectionTitle from '..';

describe('SectionTitle component', () => {
const mockData = ['home', 'previous', 'current'];

it('renders correctly with data', () => {
const { container } = render(<SectionTitle path={mockData} />);
expect(container).toMatchSnapshot();
});

it('last item should be active', () => {
render(<SectionTitle path={mockData} />);
const active = screen.getByText(mockData[mockData.length - 1]);
expect(active).toHaveClass('active');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SectionTitle component renders correctly with data 1`] = `
<div>
<div
class="sectionTitle"
>
home /
previous /
<span
class="active"
>
current
</span>
</div>
</div>
`;
13 changes: 13 additions & 0 deletions components/Common/SectionTitle/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.sectionTitle,
%section-title {
color: var(--color-text-primary);
font-size: var(--font-size-overline);
font-weight: var(--font-weight-semibold);
letter-spacing: var(--space-02);
line-height: var(--line-height-overline);
text-transform: uppercase;

.active {
color: var(--brand4);
}
}
9 changes: 9 additions & 0 deletions components/Common/SectionTitle/index.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import SectionTitle from './index';

export default { component: SectionTitle };

export const Default = {
args: {
path: ['home', 'previous', 'current'],
},
};
25 changes: 25 additions & 0 deletions components/Common/SectionTitle/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import styles from './index.module.scss';

interface Props {
path: string[];
}

const SectionTitle = ({ path }: Props) => (
<div className={styles.sectionTitle}>
{path.map((item, index) => {
const isLast = index === path.length - 1;

if (isLast) {
return (
<span className={styles.active} key={item}>
{item}
</span>
);
}

return `${item} / `;
})}
</div>
);

export default SectionTitle;

0 comments on commit eaff4f4

Please sign in to comment.