Skip to content

Commit

Permalink
Improve config access within vanilla ds
Browse files Browse the repository at this point in the history
  • Loading branch information
dabbott committed Dec 14, 2023
1 parent 0031938 commit 5e353c6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
6 changes: 4 additions & 2 deletions packages/noya-component/src/renderResolvedNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function renderResolvedNode({
dsConfig,
system,
stylingMode = 'inline',
noya,
theme,
}: {
containerWidth?: number;
contentEditable: boolean;
Expand All @@ -73,8 +73,10 @@ export function renderResolvedNode({
dsConfig: DSConfig;
system: DesignSystemDefinition;
stylingMode?: StylingMode;
noya?: any; // Passed into components as _noya
theme?: any;
}) {
const noya = { theme, dsConfig };

return ResolvedHierarchy.map<ReactNode>(
resolvedNode,
(element, transformedChildren, indexPath) => {
Expand Down
15 changes: 4 additions & 11 deletions packages/noya-module-loader/src/VanillaDesignSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import {
ButtonVariant,
DesignSystemDefinition,
Theme,
applyCommonProps,
component,
x,
Expand All @@ -23,11 +22,6 @@ const handler = {
},
};

function getTheme(props: any) {
if (props._noya && props._noya.theme) return props._noya.theme as Theme;
return undefined;
}

function getDSConfig(props: any): DSConfig {
if (props._noya && props._noya.dsConfig) return props._noya.dsConfig;
return { colorMode: 'light', colors: { primary: 'blue' } };
Expand Down Expand Up @@ -104,8 +98,7 @@ const proxyObject = new Proxy(
return <button {...applyCommonProps({ ...props, className })} />;
},
[component.id.Text]: (props: any) => {
const theme = getTheme(props);
const colorMode = theme?.colorMode || 'light';
const colorMode = getDSConfig(props).colorMode ?? 'light';

const className = [
`text-${colorMode === 'light' ? 'black' : 'white'}`,
Expand Down Expand Up @@ -189,7 +182,7 @@ const proxyObject = new Proxy(
return <img {...applyCommonProps(props)} src={props.src} />;
},
[component.id.Avatar]: (props: any) => {
const theme = getTheme(props);
const colorMode = getDSConfig(props).colorMode ?? 'light';

const className = mergeClasses(
[
Expand All @@ -198,8 +191,8 @@ const proxyObject = new Proxy(
`items-center`,
`justify-center`,
'overflow-hidden',
`bg-${theme?.colorMode === 'light' ? 'gray-100' : 'gray-800'}`,
`text-${theme?.colorMode === 'light' ? 'gray-300' : 'gray-600'}`,
`bg-${colorMode === 'light' ? 'gray-100' : 'gray-800'}`,
`text-${colorMode === 'light' ? 'gray-300' : 'gray-600'}`,
],
props.className,
);
Expand Down
1 change: 0 additions & 1 deletion packages/site/src/dseditor/renderDSPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export function renderDSPreview({
resolvedNode,
dsConfig,
system: props.system,
noya: { theme: props.theme, dsConfig },
});

const colorMode = dsConfig.colorMode ?? 'light';
Expand Down

0 comments on commit 5e353c6

Please sign in to comment.