From 51aa5f0775e9adf3b68c9cd06738d69eca720f0d Mon Sep 17 00:00:00 2001 From: Nikita Zolotykh <58661343+bocembocem@users.noreply.github.com> Date: Wed, 8 Nov 2023 18:19:50 +0300 Subject: [PATCH] feat: add layoutOpen flag for view layouts (#134) --- .../components/ViewLayouts/ViewAccordeon/ViewAccordeon.tsx | 4 +++- src/lib/kit/components/ViewLayouts/ViewCardAccordeon.tsx | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/kit/components/ViewLayouts/ViewAccordeon/ViewAccordeon.tsx b/src/lib/kit/components/ViewLayouts/ViewAccordeon/ViewAccordeon.tsx index 00606025..e2e531f7 100644 --- a/src/lib/kit/components/ViewLayouts/ViewAccordeon/ViewAccordeon.tsx +++ b/src/lib/kit/components/ViewLayouts/ViewAccordeon/ViewAccordeon.tsx @@ -12,7 +12,9 @@ export const ViewAccordeon = { - const [open, setOpen] = React.useState(true); + const [open, setOpen] = React.useState( + _.isBoolean(spec.viewSpec.layoutOpen) ? spec.viewSpec.layoutOpen : true, + ); if (!isNotEmptyValue(value, spec)) { return null; diff --git a/src/lib/kit/components/ViewLayouts/ViewCardAccordeon.tsx b/src/lib/kit/components/ViewLayouts/ViewCardAccordeon.tsx index 34a824a2..a4eb1086 100644 --- a/src/lib/kit/components/ViewLayouts/ViewCardAccordeon.tsx +++ b/src/lib/kit/components/ViewLayouts/ViewCardAccordeon.tsx @@ -1,5 +1,7 @@ import React from 'react'; +import _ from 'lodash'; + import {Card} from '../'; import {ArrayViewLayoutProps, ObjectViewLayoutProps} from '../../../core'; import {isNotEmptyValue} from '../../utils'; @@ -10,7 +12,9 @@ export const ViewCardAccordeon = { - const [open, setOpen] = React.useState(true); + const [open, setOpen] = React.useState( + _.isBoolean(spec.viewSpec.layoutOpen) ? spec.viewSpec.layoutOpen : true, + ); const onToggle = React.useCallback(() => setOpen((f) => !f), [setOpen]);