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

Accordion padding og warnings #2310

Merged
merged 4 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/itchy-bobcats-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/ds-react": patch
---

Accordion: Console.error når Accordion blir brukt feil.
5 changes: 5 additions & 0 deletions .changeset/itchy-bobcats-look2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/ds-css": patch
---

Accordion: Har nå 0.25rem padding-top mellom innhold og heading.
4 changes: 2 additions & 2 deletions @navikt/core/css/accordion.css
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@
*************************/

.navds-accordion__content {
padding: 0 var(--a-spacing-3) var(--a-spacing-5);
padding: var(--a-spacing-1) var(--a-spacing-3) var(--a-spacing-5);
animation: fadeAccordionContent 250ms ease;
}

.navds-accordion--indent > :where(.navds-accordion__item) > :where(.navds-accordion__content) {
padding: 0 var(--a-spacing-3) var(--a-spacing-5) var(--a-spacing-11);
padding: var(--a-spacing-1) var(--a-spacing-3) var(--a-spacing-5) var(--a-spacing-11);
}

.navds-accordion__content--closed {
Expand Down
1 change: 1 addition & 0 deletions @navikt/core/react/src/accordion/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const Accordion = forwardRef<HTMLDivElement, AccordionProps>(
variant,
headingSize,
size,
mounted: true,
}}
>
<div
Expand Down
3 changes: 2 additions & 1 deletion @navikt/core/react/src/accordion/AccordionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ export type AccordionContextProps = {
headingSize?: "large" | "medium" | "small" | "xsmall";
size?: "large" | "medium" | "small";
openItems?: number[];
mounted: boolean;
};

export const AccordionContext = createContext<AccordionContextProps | null>({
variant: "default",
headingSize: "small",
size: "medium",
openItems: [],
mounted: false,
});
4 changes: 2 additions & 2 deletions @navikt/core/react/src/accordion/AccordionHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const AccordionHeader = forwardRef<HTMLButtonElement, AccordionHeaderProps>(
const itemContext = useContext(AccordionItemContext);
const accordionContext = useContext(AccordionContext);

if (accordionContext === null || itemContext === null) {
if (itemContext === null) {
console.error(
"<Accordion.Header> has to be used within an <Accordion.Item>, which in turn must be within an <Accordion>"
);
Expand All @@ -45,7 +45,7 @@ const AccordionHeader = forwardRef<HTMLButtonElement, AccordionHeaderProps>(
/>
</div>
<Heading
size={accordionContext.headingSize ?? "small"}
size={accordionContext?.headingSize ?? "small"}
as="span"
className="navds-accordion__header-content"
>
Expand Down
4 changes: 4 additions & 0 deletions @navikt/core/react/src/accordion/AccordionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const AccordionItem = forwardRef<HTMLDivElement, AccordionItemProps>(
shouldAnimate.current = true;
};

if (!context?.mounted) {
console.error("<Accordion.Item> has to be used within an <Accordion>");
}

return (
<div
className={cl("navds-accordion__item", className, {
Expand Down