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

[Darkside] Popover CSS update #3369

Merged
merged 7 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
92 changes: 17 additions & 75 deletions @navikt/core/css/darkside/popover.darkside.css
Original file line number Diff line number Diff line change
@@ -1,84 +1,26 @@
.navds-popover {
z-index: var(--a-z-index-popover);
background-color: var(--ac-popover-bg, var(--a-surface-default));
box-shadow: var(--a-shadow-medium);
border: 1px solid;
border-color: var(--ac-popover-border, var(--a-border-default));
border-radius: var(--a-border-radius-large);
max-width: calc(100vw - var(--a-spacing-6));
z-index: 1000;
background: var(--ax-bg-raised);
box-shadow:
0 0 1px 0 rgba(7 9 13/ 0.02),
0 2px 5px 0 rgba(7 9 13/ 0.1),
0 5px 12px 0 rgba(7 9 13/ 0.12);
border: 1px solid var(--ax-border-subtleA);
border-radius: var(--ax-border-radius-xlarge);

/* Creates a small gutter between screen-edges on smaller devices */
max-width: calc(100vw - var(--ax-spacing-6));

&:focus-visible {
outline: 2px solid var(--ax-border-focus);
outline-offset: 2px;
}
KenAJoh marked this conversation as resolved.
Show resolved Hide resolved
}

.navds-popover__content {
padding: var(--a-spacing-4);
padding: var(--ax-spacing-4);
}

.navds-popover--hidden {
display: none;
}

.navds-popover:focus-visible {
outline: none;
box-shadow: var(--a-shadow-focus);
}

@supports not selector(:focus-visible) {
.navds-popover:focus {
outline: none;
box-shadow: var(--a-shadow-focus);
}
}

.navds-popover__arrow {
position: absolute;
z-index: -1;
transform: rotate(45deg);
background-color: var(--ac-popover-bg, var(--a-surface-default));
border: 1px solid;
border-color: var(--ac-popover-border, var(--a-border-default));
width: 1rem;
height: 1rem;
}

.navds-popover[data-placement^="top"] > .navds-popover__arrow {
border-left-color: transparent;
border-top-color: transparent;
}

/* prettier-ignore */
.navds-popover[data-placement^="bottom"] > .navds-popover__arrow {
border-bottom-color: transparent;
border-right-color: transparent;
}

.navds-popover[data-placement^="left"] > .navds-popover__arrow {
border-left-color: transparent;
border-bottom-color: transparent;
}

.navds-popover[data-placement^="right"] > .navds-popover__arrow {
border-right-color: transparent;
border-top-color: transparent;
}

@media (forced-colors: active) {
.navds-popover[data-placement^="top"] > .navds-popover__arrow {
border-left-color: canvas;
border-top-color: canvas;
}

/* prettier-ignore */
.navds-popover[data-placement^="bottom"] > .navds-popover__arrow {
border-bottom-color: canvas;
border-right-color: canvas;
}

.navds-popover[data-placement^="left"] > .navds-popover__arrow {
border-left-color: canvas;
border-bottom-color: canvas;
}

.navds-popover[data-placement^="right"] > .navds-popover__arrow {
border-right-color: canvas;
border-top-color: canvas;
}
}
8 changes: 6 additions & 2 deletions @navikt/core/react/src/popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import React, { HTMLAttributes, forwardRef, useContext, useRef } from "react";
import { DateContext } from "../date/context";
import { useModalContext } from "../modal/Modal.context";
import { DismissableLayer } from "../overlays/dismissablelayer/DismissableLayer";
import { UNSAFE_useAkselTheme } from "../provider";
import { useClientLayoutEffect } from "../util/hooks";
import { useMergeRefs } from "../util/hooks/useMergeRefs";
import PopoverContent, { PopoverContentType } from "./PopoverContent";
Expand Down Expand Up @@ -124,6 +125,8 @@ export const Popover = forwardRef<HTMLDivElement, PopoverProps>(
const chosenStrategy = userStrategy ?? (isInModal ? "fixed" : "absolute");
const chosenFlip = isInDatepicker ? false : _flip;

const themeContext = UNSAFE_useAkselTheme(false);

const {
update,
refs,
Expand All @@ -135,7 +138,7 @@ export const Popover = forwardRef<HTMLDivElement, PopoverProps>(
placement,
open,
middleware: [
flOffset(offset ?? (arrow ? 16 : 4)),
flOffset(offset ?? themeContext ? 8 : arrow ? 16 : 4),
KenAJoh marked this conversation as resolved.
Show resolved Hide resolved
chosenFlip &&
flip({ padding: 5, fallbackPlacements: ["bottom", "top"] }),
shift({ padding: 12 }),
Expand Down Expand Up @@ -187,7 +190,8 @@ export const Popover = forwardRef<HTMLDivElement, PopoverProps>(
aria-hidden={!open || !anchorEl}
>
{children}
{arrow && (
{/* Hide arrow in new design, prop will be remove din breaking change update */}
KenAJoh marked this conversation as resolved.
Show resolved Hide resolved
{arrow && !themeContext && (
<div
ref={(node) => {
arrowRef.current = node;
Expand Down
1 change: 1 addition & 0 deletions @navikt/core/react/src/popover/popover.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const Placement = () => {
);
};

/* TODO: All stories with Arrow can be removed after darkside update */
export const Arrow = () => {
return (
<div className="colgap" style={{ gap: "12rem" }}>
Expand Down
Loading