Skip to content

Commit

Permalink
feat(Header): adding prop "sticky" (#730)
Browse files Browse the repository at this point in the history
This pull request introduces a new `sticky` property to the `Header`
component and updates relevant stories and tests to accommodate this new
feature.

### New Feature: Sticky Header

*
[`packages/ui-header/src/components/Header/Header.tsx`](diffhunk://#diff-0577ff167517db4abebe26dc9be31c541bb6e4df57ff143a7eac6bf46c836df3R14):
Added a `sticky` property to the `Header` component and applied the
appropriate CSS classes when `sticky` is true.
[[1]](diffhunk://#diff-0577ff167517db4abebe26dc9be31c541bb6e4df57ff143a7eac6bf46c836df3R14)
[[2]](diffhunk://#diff-0577ff167517db4abebe26dc9be31c541bb6e4df57ff143a7eac6bf46c836df3R27)
*
[`packages/documentation/src/Components/Header.stories.tsx`](diffhunk://#diff-4db53dc21ffe9e211fb22d1279b74c1b03a721abb0bf8499925445ed290ca158R39):
Updated the story to include the new `sticky` property for the `Header`
component.
*
[`packages/ui-header/src/components/Header/__tests__/Header.test.tsx`](diffhunk://#diff-e1d425a794111d2a786df6d8eb6fe5e3a1e8db4e8518f9bc328ec653495e47faR115-R138):
Added a test case to verify that the `Header` component renders
correctly with the `sticky` property.
  • Loading branch information
aversini authored Oct 7, 2024
1 parent b09d3cf commit 627f7a6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/documentation/src/Components/Header.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default {
raw: false,
noColors: false,
mode: "system",
sticky: false,
},
argTypes: {
mode: {
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-header/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const Header = ({
spacing,
mode = "system",
noColors = false,
sticky = false,
}: HeaderProps) => {
const headerClass = clsx(HEADER_CLASSNAME, getSpacing(spacing), {
"border-border-accent bg-surface-dark":
Expand All @@ -23,6 +24,7 @@ export const Header = ({
mode === "system" && !raw && !noColors,
"border-b-4": !raw,
"border-transparent": !raw && noColors,
"sticky top-0 z-50": sticky,
});
const headerInnerClass = clsx(className, {
"mt-0 flex w-full flex-col p-2 md:mx-auto md:max-w-4xl": !raw,
Expand Down
4 changes: 4 additions & 0 deletions packages/ui-header/src/components/Header/HeaderTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ export type HeaderProps = {
* @default false
*/
raw?: boolean;
/**
* Whether or not to render the Header component with sticky behavior.
*/
sticky?: boolean;
} & SpacingProps;
24 changes: 24 additions & 0 deletions packages/ui-header/src/components/Header/__tests__/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,28 @@ describe("Header modifiers", () => {
expect(header.className).toContain(HEADER_CLASSNAME);
expect(header.className).not.toContain("mt-0");
});

it("should render a responsive header tag (system)", async () => {
render(<Header sticky>hello</Header>);
const header = await screen.findByRole("banner");
expectToHaveClasses(header, [
HEADER_CLASSNAME,
"border-border-medium",
"bg-surface-light",
"dark:border-border-accent",
"dark:bg-surface-dark",
"sticky",
"top-0",
"z-50",
]);
expectToHaveClasses(header.children[0], [
"mt-0",
"flex",
"w-full",
"flex-col",
"p-2",
"md:mx-auto",
"md:max-w-4xl",
]);
});
});

0 comments on commit 627f7a6

Please sign in to comment.