diff --git a/.changeset/quick-numbers-remain.md b/.changeset/quick-numbers-remain.md new file mode 100644 index 0000000000..19192b5de2 --- /dev/null +++ b/.changeset/quick-numbers-remain.md @@ -0,0 +1,5 @@ +--- +"@navikt/ds-react": patch +--- + +Add JSDoc typings diff --git a/@navikt/core/react/src/accordion/Accordion.tsx b/@navikt/core/react/src/accordion/Accordion.tsx index a9b61d8f0e..d63314a44a 100644 --- a/@navikt/core/react/src/accordion/Accordion.tsx +++ b/@navikt/core/react/src/accordion/Accordion.tsx @@ -1,17 +1,32 @@ import cl from "clsx"; import React, { forwardRef } from "react"; -import AccordionItem, { AccordionItemType } from "./AccordionItem"; -import AccordionContent, { AccordionContentType } from "./AccordionContent"; -import AccordionHeader, { AccordionHeaderType } from "./AccordionHeader"; +import AccordionItem, { AccordionItemProps } from "./AccordionItem"; +import AccordionContent, { AccordionContentProps } from "./AccordionContent"; +import AccordionHeader, { AccordionHeaderProps } from "./AccordionHeader"; import { AccordionContext } from "./AccordionContext"; interface AccordionComponent extends React.ForwardRefExoticComponent< AccordionProps & React.RefAttributes > { - Item: AccordionItemType; - Header: AccordionHeaderType; - Content: AccordionContentType; + /** + * @see 🏷️ {@link AccordionItemProps} + */ + Item: React.ForwardRefExoticComponent< + AccordionItemProps & React.RefAttributes + >; + /** + * @see 🏷️ {@link AccordionHeaderProps} + */ + Header: React.ForwardRefExoticComponent< + AccordionHeaderProps & React.RefAttributes + >; + /** + * @see 🏷️ {@link AccordionContentProps} + */ + Content: React.ForwardRefExoticComponent< + AccordionContentProps & React.RefAttributes + >; } export interface AccordionProps extends React.HTMLAttributes { @@ -38,6 +53,26 @@ export interface AccordionProps extends React.HTMLAttributes { children: React.ReactNode; } +/** + * A component that displays collapsible content sections. + * + * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/accordion) + * @see 🏷️ {@link AccordionProps} + * + * @example + * ```jsx + * + * + * Section 1 + * Content 1 + * + * + * Section 2 + * Content 2 + * + * + * ``` + */ export const Accordion = forwardRef( ( { diff --git a/@navikt/core/react/src/accordion/AccordionContent.tsx b/@navikt/core/react/src/accordion/AccordionContent.tsx index 6771fedeb8..dae93ac0cb 100644 --- a/@navikt/core/react/src/accordion/AccordionContent.tsx +++ b/@navikt/core/react/src/accordion/AccordionContent.tsx @@ -11,11 +11,7 @@ export interface AccordionContentProps children: React.ReactNode; } -export type AccordionContentType = React.ForwardRefExoticComponent< - AccordionContentProps & React.RefAttributes ->; - -const AccordionContent: AccordionContentType = forwardRef( +const AccordionContent = forwardRef( ({ children, className, ...rest }, ref) => { const context = useContext(AccordionItemContext); diff --git a/@navikt/core/react/src/accordion/AccordionHeader.tsx b/@navikt/core/react/src/accordion/AccordionHeader.tsx index f707ac00c3..5ce539240b 100644 --- a/@navikt/core/react/src/accordion/AccordionHeader.tsx +++ b/@navikt/core/react/src/accordion/AccordionHeader.tsx @@ -13,11 +13,7 @@ export interface AccordionHeaderProps children: React.ReactNode; } -export type AccordionHeaderType = React.ForwardRefExoticComponent< - AccordionHeaderProps & React.RefAttributes ->; - -const AccordionHeader: AccordionHeaderType = forwardRef( +const AccordionHeader = forwardRef( ({ children, className, onClick, ...rest }, ref) => { const itemContext = useContext(AccordionItemContext); const accordionContext = useContext(AccordionContext); diff --git a/@navikt/core/react/src/accordion/AccordionItem.tsx b/@navikt/core/react/src/accordion/AccordionItem.tsx index 5141d9d789..d329479ca6 100644 --- a/@navikt/core/react/src/accordion/AccordionItem.tsx +++ b/@navikt/core/react/src/accordion/AccordionItem.tsx @@ -27,10 +27,6 @@ export interface AccordionItemProps defaultOpen?: boolean; } -export type AccordionItemType = React.ForwardRefExoticComponent< - AccordionItemProps & React.RefAttributes ->; - export interface AccordionItemContextProps { open: boolean; toggleOpen: () => void; @@ -39,7 +35,7 @@ export interface AccordionItemContextProps { export const AccordionItemContext = createContext(null); -const AccordionItem: AccordionItemType = forwardRef( +const AccordionItem = forwardRef( ( { children, className, open, defaultOpen = false, onClick, id, ...rest }, ref diff --git a/@navikt/core/react/src/alert/Alert.tsx b/@navikt/core/react/src/alert/Alert.tsx index 7e9425e008..1824d91284 100644 --- a/@navikt/core/react/src/alert/Alert.tsx +++ b/@navikt/core/react/src/alert/Alert.tsx @@ -53,6 +53,15 @@ export interface AlertContextProps { size: "medium" | "small"; } +/** + * A component for displaying alerts + * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/alert) + * @see 🏷️ {@link AlertProps} + * @example + * ```jsx + * Dette er en feilmelding + * ``` + */ export const Alert = forwardRef( ( { diff --git a/@navikt/core/react/src/button/Button.tsx b/@navikt/core/react/src/button/Button.tsx index 13705b81d7..3679b5698c 100644 --- a/@navikt/core/react/src/button/Button.tsx +++ b/@navikt/core/react/src/button/Button.tsx @@ -47,6 +47,16 @@ export interface ButtonProps iconPosition?: "left" | "right"; } +/** + * A button component + * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/button) + * @see 🏷️ {@link ButtonProps} + * @see [🤖 OverridableComponent](https://aksel.nav.no/grunnleggende/kode/overridablecomponent) support + * @example + * ```jsx + * + * ``` + */ export const Button: OverridableComponent = forwardRef( ( diff --git a/@navikt/core/react/src/chat/Bubble.tsx b/@navikt/core/react/src/chat/Bubble.tsx index dfd1f7681f..3314332694 100644 --- a/@navikt/core/react/src/chat/Bubble.tsx +++ b/@navikt/core/react/src/chat/Bubble.tsx @@ -25,11 +25,7 @@ export interface BubbleProps extends HTMLAttributes { toptextPosition?: "left" | "right"; } -export type BubbleType = React.ForwardRefExoticComponent< - BubbleProps & React.RefAttributes ->; - -const Bubble: BubbleType = forwardRef( +const Bubble = forwardRef( ( { children, diff --git a/@navikt/core/react/src/chat/Chat.tsx b/@navikt/core/react/src/chat/Chat.tsx index 25bee065a0..dd4a79f52c 100644 --- a/@navikt/core/react/src/chat/Chat.tsx +++ b/@navikt/core/react/src/chat/Chat.tsx @@ -1,6 +1,6 @@ import React, { forwardRef, HTMLAttributes } from "react"; import cl from "clsx"; -import Bubble, { BubbleType } from "./Bubble"; +import Bubble, { BubbleProps } from "./Bubble"; import { BodyLong, BodyShort } from "../typography"; export interface ChatProps extends HTMLAttributes { @@ -44,9 +44,30 @@ interface ChatComponent extends React.ForwardRefExoticComponent< ChatProps & React.RefAttributes > { - Bubble: BubbleType; + /** + * @see 🏷️ {@link BubbleProps} + */ + Bubble: React.ForwardRefExoticComponent< + BubbleProps & React.RefAttributes + >; } +/** + * A component for displaying chat messages. + * + * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/chat) + * @see 🏷️ {@link ChatProps} + * + * @example + * ```jsx + * + * Hello! + * + * + * Hi there! + * + * ``` + */ export const Chat = forwardRef( ( { diff --git a/@navikt/core/react/src/chips/Chips.tsx b/@navikt/core/react/src/chips/Chips.tsx index fe94ce97fd..f220a1ebaf 100644 --- a/@navikt/core/react/src/chips/Chips.tsx +++ b/@navikt/core/react/src/chips/Chips.tsx @@ -1,7 +1,8 @@ import cl from "clsx"; import React, { forwardRef, HTMLAttributes } from "react"; -import ToggleChips, { ToggleChipsType } from "./Toggle"; -import RemovableChips, { RemovableChipsType } from "./Removable"; +import ToggleChips, { ToggleChipsProps } from "./Toggle"; +import RemovableChips, { RemovableChipsProps } from "./Removable"; +import { OverridableComponent } from "../util/OverridableComponent"; export interface ChipsProps extends HTMLAttributes { children: React.ReactNode; @@ -16,10 +17,47 @@ interface ChipsComponent extends React.ForwardRefExoticComponent< ChipsProps & React.RefAttributes > { - Toggle: ToggleChipsType; - Removable: RemovableChipsType; + /** + * Toggle between selected-states. + * @see 🏷️ {@link ToggleChipsProps} + * @see [🤖 OverridableComponent](https://aksel.nav.no/grunnleggende/kode/overridablecomponent) support + */ + Toggle: OverridableComponent; + /** + * Remove filter or the likes on click + * @see 🏷️ {@link RemovableChipsProps} + * @see [🤖 OverridableComponent](https://aksel.nav.no/grunnleggende/kode/overridablecomponent) support + */ + Removable: OverridableComponent; } +/** + * A component that displays a list of items as chips. + * + * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/chips) + * @see 🏷️ {@link ChipsProps} + * + * @example + * ```jsx + + {options.map((c) => ( + + setSelected( + selected.includes(c) + ? selected.filter((x) => x !== c) + : [...selected, c] + ) + } + > + {c} + + ))} + + * ``` + */ export const Chips: ChipsComponent = forwardRef( ({ className, size = "medium", children, ...rest }, ref) => { return ( diff --git a/@navikt/core/react/src/chips/Removable.tsx b/@navikt/core/react/src/chips/Removable.tsx index 65497ca58e..ea583d787e 100644 --- a/@navikt/core/react/src/chips/Removable.tsx +++ b/@navikt/core/react/src/chips/Removable.tsx @@ -22,9 +22,6 @@ export interface RemovableChipsProps onDelete?: () => void; } -export interface RemovableChipsType - extends OverridableComponent {} - export const RemovableChips: OverridableComponent< RemovableChipsProps, HTMLButtonElement @@ -63,6 +60,6 @@ export const RemovableChips: OverridableComponent< ); } -) as RemovableChipsType; +); export default RemovableChips; diff --git a/@navikt/core/react/src/chips/Toggle.tsx b/@navikt/core/react/src/chips/Toggle.tsx index 1da34f3b98..323cf44652 100644 --- a/@navikt/core/react/src/chips/Toggle.tsx +++ b/@navikt/core/react/src/chips/Toggle.tsx @@ -12,10 +12,10 @@ export interface ToggleChipsProps selected?: boolean; } -export interface ToggleChipsType - extends OverridableComponent {} - -export const ToggleChips: ToggleChipsType = forwardRef( +export const ToggleChips: OverridableComponent< + ToggleChipsProps, + HTMLButtonElement +> = forwardRef( ( { className, children, selected, as: Component = "button", ...rest }, ref diff --git a/@navikt/core/react/src/copybutton/CopyButton.tsx b/@navikt/core/react/src/copybutton/CopyButton.tsx index 43ad46e6fa..4b49c9938c 100644 --- a/@navikt/core/react/src/copybutton/CopyButton.tsx +++ b/@navikt/core/react/src/copybutton/CopyButton.tsx @@ -65,6 +65,17 @@ export interface CopyButtonProps activeTitle?: string; } +/** + * A button component that copies text to the clipboard when clicked. + * + * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/copybutton) + * @see 🏷️ {@link CopyButtonProps} + * + * @example + * ```jsx + + * ``` + */ export const CopyButton = forwardRef( ( { diff --git a/@navikt/core/react/src/date/DateInput.tsx b/@navikt/core/react/src/date/DateInput.tsx index 4c3f0c171e..871ca97a28 100644 --- a/@navikt/core/react/src/date/DateInput.tsx +++ b/@navikt/core/react/src/date/DateInput.tsx @@ -28,131 +28,121 @@ export interface DateInputProps variant?: "datepicker" | "monthpicker"; } -export type DateInputType = React.ForwardRefExoticComponent< - DateInputProps & React.RefAttributes ->; +const DateInput = forwardRef((props, ref) => { + const { + className, + hideLabel = false, + label, + description, + variant = "datepicker", + ...rest + } = props; -const DateInput: DateInputType = forwardRef( - (props, ref) => { - const { - className, - hideLabel = false, - label, - description, - variant = "datepicker", - ...rest - } = props; + const isDatepickerVariant = variant === "datepicker"; - const isDatepickerVariant = variant === "datepicker"; + const conditionalVariables = { + prefix: isDatepickerVariant ? "datepicker-input" : "monthpicker-input", + iconTitle: { + open: isDatepickerVariant ? "Åpne datovelger" : "Åpne månedsvelger", + close: isDatepickerVariant ? "Lukk datovelger" : "Lukk månedsvelger", + }, + }; - const conditionalVariables = { - prefix: isDatepickerVariant ? "datepicker-input" : "monthpicker-input", - iconTitle: { - open: isDatepickerVariant ? "Åpne datovelger" : "Åpne månedsvelger", - close: isDatepickerVariant ? "Lukk datovelger" : "Lukk månedsvelger", - }, - }; + const { onOpen, ariaId, open } = useDateInputContext(); - const { onOpen, ariaId, open } = useDateInputContext(); + const { + inputProps, + size = "medium", + inputDescriptionId, + errorId, + showErrorMsg, + hasError, + } = useFormField(props, conditionalVariables.prefix); - const { - inputProps, - size = "medium", - inputDescriptionId, - errorId, - showErrorMsg, - hasError, - } = useFormField(props, conditionalVariables.prefix); - - return ( -
+