From d52e2bd5146f5b41607a6ddc84c2717f3a8fdcf0 Mon Sep 17 00:00:00 2001 From: Ken Date: Tue, 17 Dec 2024 17:16:55 +0100 Subject: [PATCH 1/6] :truck: Rename and move theme-component --- .../react/src/accordion/AccordionContent.tsx | 4 +- .../react/src/accordion/AccordionHeader.tsx | 4 +- .../src/date/datepicker/parts/WeekNumber.tsx | 4 +- @navikt/core/react/src/form/search/Search.tsx | 4 +- @navikt/core/react/src/form/switch/Switch.tsx | 4 +- .../core/react/src/guide-panel/GuidePanel.tsx | 4 +- @navikt/core/react/src/help-text/HelpText.tsx | 4 +- .../src/internal-header/InternalHeader.tsx | 8 +-- .../react/src/layout/base/BasePrimitive.tsx | 4 +- @navikt/core/react/src/layout/bleed/Bleed.tsx | 4 +- @navikt/core/react/src/layout/box/Box.tsx | 4 +- @navikt/core/react/src/layout/grid/HGrid.tsx | 4 +- @navikt/core/react/src/layout/page/Page.tsx | 4 +- @navikt/core/react/src/layout/stack/Stack.tsx | 4 +- .../src/overlays/action-menu/ActionMenu.tsx | 4 +- .../react/src/pagination/PaginationItem.tsx | 4 +- @navikt/core/react/src/popover/Popover.tsx | 4 +- @navikt/core/react/src/provider/index.ts | 4 -- .../react/src/provider/theme/AkselTheme.tsx | 70 ------------------- @navikt/core/react/src/read-more/ReadMore.tsx | 5 +- @navikt/core/react/src/theme/Theme.tsx | 60 ++++++++++++++++ @navikt/core/react/src/theme/index.ts | 2 + @navikt/core/react/src/timeline/Pin.tsx | 4 +- .../src/timeline/period/ClickablePeriod.tsx | 4 +- @navikt/core/react/src/tooltip/Tooltip.tsx | 4 +- 25 files changed, 105 insertions(+), 120 deletions(-) delete mode 100644 @navikt/core/react/src/provider/theme/AkselTheme.tsx create mode 100644 @navikt/core/react/src/theme/Theme.tsx create mode 100644 @navikt/core/react/src/theme/index.ts diff --git a/@navikt/core/react/src/accordion/AccordionContent.tsx b/@navikt/core/react/src/accordion/AccordionContent.tsx index 30b125f0bb..ba52711388 100644 --- a/@navikt/core/react/src/accordion/AccordionContent.tsx +++ b/@navikt/core/react/src/accordion/AccordionContent.tsx @@ -1,6 +1,6 @@ import cl from "clsx"; import React, { forwardRef, useContext } from "react"; -import { UNSAFE_useAkselTheme } from "../provider"; +import { useThemeInternal } from "../theme/Theme"; import { BodyLong } from "../typography"; import { AccordionItemContext } from "./AccordionItem"; @@ -16,7 +16,7 @@ const AccordionContent = forwardRef( ({ children, className, ...rest }, ref) => { const context = useContext(AccordionItemContext); - const themeContext = UNSAFE_useAkselTheme(false); + const themeContext = useThemeInternal(); if (context === null) { console.error( diff --git a/@navikt/core/react/src/accordion/AccordionHeader.tsx b/@navikt/core/react/src/accordion/AccordionHeader.tsx index 98e26ae47f..dd99b1de17 100644 --- a/@navikt/core/react/src/accordion/AccordionHeader.tsx +++ b/@navikt/core/react/src/accordion/AccordionHeader.tsx @@ -1,7 +1,7 @@ import cl from "clsx"; import React, { forwardRef, useContext } from "react"; import { ChevronDownIcon } from "@navikt/aksel-icons"; -import { UNSAFE_useAkselTheme } from "../provider"; +import { useThemeInternal } from "../theme/Theme"; import { Heading } from "../typography"; import { composeEventHandlers } from "../util/composeEventHandlers"; import { AccordionContext } from "./AccordionContext"; @@ -20,7 +20,7 @@ const AccordionHeader = forwardRef( const itemContext = useContext(AccordionItemContext); const accordionContext = useContext(AccordionContext); - const themeContext = UNSAFE_useAkselTheme(false); + const themeContext = useThemeInternal(); if (itemContext === null) { console.error( diff --git a/@navikt/core/react/src/date/datepicker/parts/WeekNumber.tsx b/@navikt/core/react/src/date/datepicker/parts/WeekNumber.tsx index 5a2ac8035b..93061bbeb4 100644 --- a/@navikt/core/react/src/date/datepicker/parts/WeekNumber.tsx +++ b/@navikt/core/react/src/date/datepicker/parts/WeekNumber.tsx @@ -2,7 +2,7 @@ import React from "react"; import { Button as RDPButton, useDayPicker } from "react-day-picker"; import { Button } from "../../../button"; -import { UNSAFE_useAkselTheme } from "../../../provider"; +import { useThemeInternal } from "../../../theme/Theme"; import { Detail } from "../../../typography"; import { useDateTranslationContext } from "../../context"; @@ -21,7 +21,7 @@ function WeekNumber({ dates, }: WeekNumberProps): JSX.Element { const { onWeekNumberClick, styles, classNames } = useDayPicker(); - const themeContext = UNSAFE_useAkselTheme(false); + const themeContext = useThemeInternal(); const translate = useDateTranslationContext().translate; if (!onWeekNumberClick) { diff --git a/@navikt/core/react/src/form/search/Search.tsx b/@navikt/core/react/src/form/search/Search.tsx index ce77637ddd..0a0eebcfb8 100644 --- a/@navikt/core/react/src/form/search/Search.tsx +++ b/@navikt/core/react/src/form/search/Search.tsx @@ -7,7 +7,7 @@ import React, { } from "react"; import { MagnifyingGlassIcon, XMarkIcon } from "@navikt/aksel-icons"; import { Button } from "../../button"; -import { UNSAFE_useAkselTheme } from "../../provider"; +import { useThemeInternal } from "../../theme/Theme"; import { BodyShort, ErrorMessage, Label } from "../../typography"; import { omit } from "../../util"; import { useMergeRefs } from "../../util/hooks/useMergeRefs"; @@ -125,7 +125,7 @@ export const Search = forwardRef( ...rest } = props; - const themeContext = UNSAFE_useAkselTheme(false); + const themeContext = useThemeInternal(); const searchRef = useRef(null); const mergedRef = useMergeRefs(searchRef, ref); diff --git a/@navikt/core/react/src/form/switch/Switch.tsx b/@navikt/core/react/src/form/switch/Switch.tsx index fe3d3bc385..12848eaf45 100644 --- a/@navikt/core/react/src/form/switch/Switch.tsx +++ b/@navikt/core/react/src/form/switch/Switch.tsx @@ -6,7 +6,7 @@ import React, { useState, } from "react"; import { Loader } from "../../loader"; -import { UNSAFE_useAkselTheme } from "../../provider"; +import { useThemeInternal } from "../../theme/Theme"; import { BodyShort } from "../../typography"; import { omit } from "../../util"; import { ReadOnlyIconWithTitle } from "../ReadOnlyIcon"; @@ -69,7 +69,7 @@ export const Switch = forwardRef( defaultChecked ?? checkedProp ?? false, ); - const themeContext = UNSAFE_useAkselTheme(false); + const themeContext = useThemeInternal(); useEffect(() => { checkedProp !== undefined && setChecked(checkedProp); diff --git a/@navikt/core/react/src/guide-panel/GuidePanel.tsx b/@navikt/core/react/src/guide-panel/GuidePanel.tsx index a01abed4f8..e419cef20a 100644 --- a/@navikt/core/react/src/guide-panel/GuidePanel.tsx +++ b/@navikt/core/react/src/guide-panel/GuidePanel.tsx @@ -1,6 +1,6 @@ import cl from "clsx"; import React, { HTMLAttributes, forwardRef } from "react"; -import { UNSAFE_useAkselTheme } from "../provider"; +import { useThemeInternal } from "../theme/Theme"; import { DefaultIllustration } from "./Illustration"; import { DarksideGudiepanelIllustration } from "./Illustration.darkside"; @@ -37,7 +37,7 @@ export interface GuidePanelProps extends HTMLAttributes { */ export const GuidePanel = forwardRef( ({ children, className, illustration, poster, ...rest }, ref) => { - const themeContext = UNSAFE_useAkselTheme(false); + const themeContext = useThemeInternal(); return (
( const buttonRef = useRef(null); const mergedRef = useMergeRefs(buttonRef, ref); const [open, setOpen] = useState(false); - const themeContext = UNSAFE_useAkselTheme(false); + const themeContext = useThemeInternal(); const translate = useI18n("HelpText"); const titleWithFallback = title || translate("title"); diff --git a/@navikt/core/react/src/internal-header/InternalHeader.tsx b/@navikt/core/react/src/internal-header/InternalHeader.tsx index bb135378bb..6b9be66cd2 100644 --- a/@navikt/core/react/src/internal-header/InternalHeader.tsx +++ b/@navikt/core/react/src/internal-header/InternalHeader.tsx @@ -1,6 +1,6 @@ import cl from "clsx"; import React, { HTMLAttributes, forwardRef } from "react"; -import { UNSAFE_AkselTheme, UNSAFE_useAkselTheme } from "../provider"; +import { Theme, useThemeInternal } from "../theme/Theme"; import { OverridableComponent } from "../util/types"; import InternalHeaderButton, { InternalHeaderButtonProps, @@ -78,20 +78,20 @@ interface InternalHeaderComponent * ``` */ export const InternalHeader = forwardRef(({ className, ...rest }, ref) => { - const themeContext = UNSAFE_useAkselTheme(false); + const themeContext = useThemeInternal(); /* * Component is always in "dark" mode, so we manually override global theme. */ if (themeContext) { return ( - +
- + ); } diff --git a/@navikt/core/react/src/layout/base/BasePrimitive.tsx b/@navikt/core/react/src/layout/base/BasePrimitive.tsx index 064bd46f44..d687db0bd7 100644 --- a/@navikt/core/react/src/layout/base/BasePrimitive.tsx +++ b/@navikt/core/react/src/layout/base/BasePrimitive.tsx @@ -1,7 +1,7 @@ import cl from "clsx"; import React from "react"; -import { UNSAFE_useAkselTheme } from "../../provider"; import { Slot } from "../../slot/Slot"; +import { useThemeInternal } from "../../theme/Theme"; import { getResponsiveProps, getResponsiveValue } from "../utilities/css"; import { ResponsiveProp, SpacingScale } from "../utilities/types"; @@ -252,7 +252,7 @@ export const BasePrimitive = ({ flexShrink, gridColumn, }: BasePrimitiveProps) => { - const themeContext = UNSAFE_useAkselTheme(false); + const themeContext = useThemeInternal(); const prefix = themeContext ? "ax" : "a"; const style: React.CSSProperties = { diff --git a/@navikt/core/react/src/layout/bleed/Bleed.tsx b/@navikt/core/react/src/layout/bleed/Bleed.tsx index 2aa5b83c73..2a677af488 100644 --- a/@navikt/core/react/src/layout/bleed/Bleed.tsx +++ b/@navikt/core/react/src/layout/bleed/Bleed.tsx @@ -1,7 +1,7 @@ import cl from "clsx"; import React, { forwardRef } from "react"; -import { UNSAFE_useAkselTheme } from "../../provider"; import { Slot } from "../../slot/Slot"; +import { useThemeInternal } from "../../theme/Theme"; import { getResponsiveProps } from "../utilities/css"; import { ResponsiveProp, SpacingScale } from "../utilities/types"; @@ -81,7 +81,7 @@ export const Bleed = forwardRef( }, ref, ) => { - const themeContext = UNSAFE_useAkselTheme(false); + const themeContext = useThemeInternal(); const prefix = themeContext ? "ax" : "a"; let style: React.CSSProperties = { diff --git a/@navikt/core/react/src/layout/box/Box.tsx b/@navikt/core/react/src/layout/box/Box.tsx index 0b79d1e2ab..8a1a83254c 100644 --- a/@navikt/core/react/src/layout/box/Box.tsx +++ b/@navikt/core/react/src/layout/box/Box.tsx @@ -1,8 +1,8 @@ import cl from "clsx"; import React, { forwardRef } from "react"; import { type BorderRadiusKeys } from "@navikt/ds-tokens/types"; -import { UNSAFE_useAkselTheme } from "../../provider"; import { Slot } from "../../slot/Slot"; +import { useThemeInternal } from "../../theme/Theme"; import { omit } from "../../util"; import { OverridableComponent } from "../../util/types"; import BasePrimitive, { @@ -109,7 +109,7 @@ export const BoxComponent: OverridableComponent = }, ref, ) => { - const themeContext = UNSAFE_useAkselTheme(false); + const themeContext = useThemeInternal(); if ( process.env.NODE_ENV !== "production" && diff --git a/@navikt/core/react/src/layout/grid/HGrid.tsx b/@navikt/core/react/src/layout/grid/HGrid.tsx index e894968274..a462fca8cb 100644 --- a/@navikt/core/react/src/layout/grid/HGrid.tsx +++ b/@navikt/core/react/src/layout/grid/HGrid.tsx @@ -1,7 +1,7 @@ import cl from "clsx"; import React, { forwardRef } from "react"; -import { UNSAFE_useAkselTheme } from "../../provider"; import { Slot } from "../../slot/Slot"; +import { useThemeInternal } from "../../theme/Theme"; import { OverridableComponent, omit } from "../../util"; import BasePrimitive, { PRIMITIVE_PROPS, @@ -78,7 +78,7 @@ export const HGrid: OverridableComponent = }, ref, ) => { - const themeContext = UNSAFE_useAkselTheme(false); + const themeContext = useThemeInternal(); const prefix = themeContext ? "ax" : "a"; const styles: React.CSSProperties = { diff --git a/@navikt/core/react/src/layout/page/Page.tsx b/@navikt/core/react/src/layout/page/Page.tsx index 598ec3b4af..f0d0555fbc 100644 --- a/@navikt/core/react/src/layout/page/Page.tsx +++ b/@navikt/core/react/src/layout/page/Page.tsx @@ -1,6 +1,6 @@ import cl from "clsx"; import React, { forwardRef } from "react"; -import { UNSAFE_useAkselTheme } from "../../provider"; +import { useThemeInternal } from "../../theme/Theme"; import { OverridableComponent } from "../../util"; import { BackgroundColorToken } from "../utilities/types"; import { PageBlock } from "./parts/PageBlock"; @@ -54,7 +54,7 @@ export const PageComponent: OverridableComponent = }, ref, ) => { - const themeContext = UNSAFE_useAkselTheme(false); + const themeContext = useThemeInternal(); if (process.env.NODE_ENV !== "production" && themeContext && background) { console.warn( diff --git a/@navikt/core/react/src/layout/stack/Stack.tsx b/@navikt/core/react/src/layout/stack/Stack.tsx index 880b36cdb3..6b2af88c39 100644 --- a/@navikt/core/react/src/layout/stack/Stack.tsx +++ b/@navikt/core/react/src/layout/stack/Stack.tsx @@ -1,7 +1,7 @@ import cl from "clsx"; import React, { HTMLAttributes, forwardRef } from "react"; -import { UNSAFE_useAkselTheme } from "../../provider"; import { Slot } from "../../slot/Slot"; +import { useThemeInternal } from "../../theme/Theme"; import { omit } from "../../util"; import { OverridableComponent } from "../../util/types"; import BasePrimitive, { @@ -84,7 +84,7 @@ export const Stack: OverridableComponent = }, ref, ) => { - const themeContext = UNSAFE_useAkselTheme(false); + const themeContext = useThemeInternal(); const prefix = themeContext ? "ax" : "a"; const style: React.CSSProperties = { diff --git a/@navikt/core/react/src/overlays/action-menu/ActionMenu.tsx b/@navikt/core/react/src/overlays/action-menu/ActionMenu.tsx index c159cd0ccc..18331ff66a 100644 --- a/@navikt/core/react/src/overlays/action-menu/ActionMenu.tsx +++ b/@navikt/core/react/src/overlays/action-menu/ActionMenu.tsx @@ -2,8 +2,8 @@ import cl from "clsx"; import React, { forwardRef, useRef } from "react"; import { ChevronRightIcon } from "@navikt/aksel-icons"; import { useModalContext } from "../../modal/Modal.context"; -import { UNSAFE_useAkselTheme } from "../../provider"; import { Slot } from "../../slot/Slot"; +import { useThemeInternal } from "../../theme/Theme"; import { OverridableComponent, useId } from "../../util"; import { composeEventHandlers } from "../../util/composeEventHandlers"; import { createContext } from "../../util/create-context"; @@ -736,7 +736,7 @@ export const ActionMenuRadioItem = forwardRef< { children, className, onSelect, ...rest }: ActionMenuRadioItemProps, ref, ) => { - const themeContext = UNSAFE_useAkselTheme(false); + const themeContext = useThemeInternal(); return ( { - const themeContext = UNSAFE_useAkselTheme(false); + const themeContext = useThemeInternal(); return (
-
+ {/*

BrandVolumeHigh

{BrandVolumeHigh?.render?.(...props)} -
+
*/} ); }, From 764dc111b85c0833a9f888ecc93975634f912bfb Mon Sep 17 00:00:00 2001 From: Ken <26967723+KenAJoh@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:35:19 +0100 Subject: [PATCH 5/6] Update @navikt/core/react/src/theme/Theme.tsx --- @navikt/core/react/src/theme/Theme.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/@navikt/core/react/src/theme/Theme.tsx b/@navikt/core/react/src/theme/Theme.tsx index f2523aa3b3..416c30c072 100644 --- a/@navikt/core/react/src/theme/Theme.tsx +++ b/@navikt/core/react/src/theme/Theme.tsx @@ -9,7 +9,7 @@ type ThemeContext = { * Color theme * @default "light" */ - theme?: "light" | "dark"; + theme: "light" | "dark"; }; const [ThemeProvider, useThemeInternal] = createContext({ From 2a41a0f953db6f09a84e3277ec7b97d2c5cda304 Mon Sep 17 00:00:00 2001 From: Ken Date: Fri, 20 Dec 2024 09:28:58 +0100 Subject: [PATCH 6/6] :memo: remove commented out code --- .../react/src/read-more/readmore.stories.tsx | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/@navikt/core/react/src/read-more/readmore.stories.tsx b/@navikt/core/react/src/read-more/readmore.stories.tsx index 5d60b137d5..86d1cfe3ae 100644 --- a/@navikt/core/react/src/read-more/readmore.stories.tsx +++ b/@navikt/core/react/src/read-more/readmore.stories.tsx @@ -83,23 +83,6 @@ export const BrandVolumeLow: Story = { }, }; -/* High volume temp disabled until we agree on concept */ -/* export const BrandVolumeHigh: Story = { - render: () => ( - - - - {Content} - - {Content} - - {Content} - - - - ), -}; */ - export const Chromatic: Story = { render: (...props) => { return ( @@ -133,10 +116,6 @@ export const Chromatic: Story = {

BrandVolumeLow

{BrandVolumeLow?.render?.(...props)} - {/*
-

BrandVolumeHigh

- {BrandVolumeHigh?.render?.(...props)} -
*/} ); },