Skip to content

Commit

Permalink
Move setting-context-pane to sdk
Browse files Browse the repository at this point in the history
Signed-off-by: Zvonimir Fras <[email protected]>
  • Loading branch information
zvonimirfras committed Feb 9, 2024
1 parent 6a59850 commit b81bbb9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
9 changes: 7 additions & 2 deletions app/src/routes/edit/elements-pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ import { ChevronDown, ChevronUp } from '@carbon/react/icons';
import Handlebars from 'handlebars';
import parse from 'html-react-parser';

import { ElementTile, FragmentPreview, allComponents, FragmentLayoutWidget } from '@carbon-builder/sdk-react';
import {
ElementTile,
FragmentPreview,
allComponents,
FragmentLayoutWidget,
accordionButtonStyle
} from '@carbon-builder/sdk-react';
import { leftPane, leftPaneContent, leftPaneHeader } from '.';
import { GlobalStateContext, useFragment } from '../../context';
import { getEditScreenParams } from '../../utils/fragment-tools';
import { accordionButtonStyle } from './settings-context-pane';
import { useRemoteCustomComponentsCollections } from '../../utils/misc-tools';

const elementTileListStyleBase = css`
Expand Down
14 changes: 11 additions & 3 deletions app/src/routes/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ import { ElementsPane } from './elements-pane';
import { StylePane } from './style-pane';
import { CodePane } from './code-pane';

import { SettingsContextPane } from './settings-context-pane';
import { CodeContextPane } from './code-context-pane';
import { useParams } from 'react-router-dom';
import { useHotkeys } from 'react-hotkeys-hook';
import {
Fragment,
SettingsContextPane,
getParentComponent,
getSelectedComponent,
initializeIds,
Expand Down Expand Up @@ -191,7 +191,9 @@ export const Edit = () => {
undoAction,
redoAction,
customComponentsCollections,
styleClasses
styleClasses,
settings,
setSettings
} = useContext(GlobalStateContext);
const [remoteCustomComponentsCollections] = useRemoteCustomComponentsCollections();

Expand Down Expand Up @@ -339,7 +341,13 @@ export const Edit = () => {
</TabList>
<TabPanels>
<TabPanel>
<SettingsContextPane fragment={fragment} setFragment={updateFragment} />
<SettingsContextPane
fragment={fragment}
setFragment={updateFragment}
settings={settings}
setSettings={setSettings}
styleClasses={styleClasses}
customComponentsCollections={customComponentsCollections} />
</TabPanel>
<TabPanel>
<CodeContextPane fragment={fragment} setFragment={updateFragment} />
Expand Down
1 change: 1 addition & 0 deletions sdk/react/src/lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './fragment-layout-widget';
export * from './fragment-preview';
export * from './custom-components-collection-editor';
export * from './fragment';
export * from './settings-context-pane';
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import React from 'react';

import { Breadcrumb, BreadcrumbItem } from '@carbon/react';

import { useFragment } from '../../context';
import { css } from 'emotion';
import { getParentComponent, getSelectedComponent } from '@carbon-builder/sdk-react';
import { getParentComponent, getSelectedComponent } from '../..';

const getAncestors = (state: any, component: any) => {
const ancestors: any[] = [];
Expand All @@ -25,9 +24,7 @@ const getAncestors = (state: any, component: any) => {
return ancestors;
};

export const SelectedComponentBreadcrumbs = ({ selectedComponent }: any) => {
const [fragment, setFragment] = useFragment();

export const SelectedComponentBreadcrumbs = ({ selectedComponent, fragment, setFragment }: any) => {
if (!selectedComponent) {
selectedComponent = getSelectedComponent(fragment);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext } from 'react';
import React from 'react';
import {
Button,
Checkbox,
Expand All @@ -18,9 +18,8 @@ import {
LayoutWidget,
getSelectedComponent,
updatedState
} from '@carbon-builder/sdk-react';
} from '../..';
import { SelectedComponentBreadcrumbs } from './selected-component-breadcrumbs';
import { GlobalStateContext } from '../../context';

const styleContextPaneStyle = css`
.cds--form-item.cds--checkbox-wrapper {
Expand Down Expand Up @@ -160,15 +159,15 @@ const throttledSetComponent = throttle((component: any) => setComponent(componen
let proxySetFragment = (_fragment: any) => console.log('proxySetFragment not inizialized yet');
const throttledSetFragment = throttle((fragment: any) => proxySetFragment(fragment), 150);

export const SettingsContextPane = ({ fragment, setFragment }: any) => {
export const SettingsContextPane = ({
fragment,
setFragment,
settings,
setSettings,
styleClasses,
customComponentsCollections
}: any) => {
const selectedComponent = getSelectedComponent(fragment);
const {
settings,
setSettings,
styleClasses,
customComponentsCollections
} = useContext(GlobalStateContext);

const updateContextPaneSettings = (s: any) => {
setSettings({
...settings,
Expand Down

0 comments on commit b81bbb9

Please sign in to comment.