Skip to content

Commit

Permalink
feat: legg til defaultOpen som prop i ExpandablePanel
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #4420
  • Loading branch information
olejorgenbakken authored and piofinn committed Jan 9, 2025
1 parent 4b61d81 commit 3305bac
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/expandable-react/src/ExpandablePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ export const ExpandablePanel = Object.assign(
as = "details",
variant = "fill",
open: controlledOpen,
defaultOpen,
onOpenChange,
...rest
} = props;

const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
const [uncontrolledOpen, setUncontrolledOpen] = useState(
defaultOpen || false,
);
const [contentIsVisible, setContentIsVisible] = useState(false);
const [expanderHeight, setExpanderHeight] = useState(0);

Expand Down
4 changes: 4 additions & 0 deletions packages/expandable-react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export type ExpandablePanelProps<ElementType extends React.ElementType> =
{
variant?: "fill" | "stroke";
open?: boolean;
/*
* Initiell state av content.
*/
defaultOpen?: boolean;
onOpenChange?: (open: boolean) => void;
}
>;
Expand Down
5 changes: 4 additions & 1 deletion packages/jokul/src/components/expander/ExpandablePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ export const ExpandablePanel = Object.assign(
as = "details",
variant = "fill",
open: controlledOpen,
defaultOpen,
onOpenChange,
...rest
} = props;

const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
const [uncontrolledOpen, setUncontrolledOpen] = useState(
defaultOpen || false,
);
const [contentIsVisible, setContentIsVisible] = useState(false);
const [expanderHeight, setExpanderHeight] = useState(0);

Expand Down
4 changes: 4 additions & 0 deletions packages/jokul/src/components/expander/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export type ExpandablePanelProps<ElementType extends React.ElementType> =
{
variant?: "fill" | "stroke";
open?: boolean;
/*
* Initiell state av content.
*/
defaultOpen?: boolean;
onOpenChange?: (open: boolean) => void;
}
>;
Expand Down

0 comments on commit 3305bac

Please sign in to comment.