Skip to content

Commit

Permalink
feat: import buildMergeOverrides from amplify-ui (#316)
Browse files Browse the repository at this point in the history
Importing buildMergeOverrides from amplify-ui package
  • Loading branch information
dhandsar-aws authored and alharris-at committed Feb 25, 2022
1 parent ad941cd commit 5b2b838
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 307 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ import {
Variant,
getOverrideProps,
getOverridesFromVariants,
mergeVariantsAndOverrides,
} from \\"@aws-amplify/ui-react/internal\\";
import { Flex, FlexProps, View } from \\"@aws-amplify/ui-react\\";
Expand Down Expand Up @@ -922,26 +923,6 @@ export default function ComplexTest4(
variantValues: { colors: \\"Red/Orange\\" },
},
];
const mergeVariantsAndOverrides = (
variants: EscapeHatchProps,
overrides: EscapeHatchProps
): EscapeHatchProps => {
const overrideKeys = new Set(Object.keys(overrides));
const sharedKeys = Object.keys(variants).filter((variantKey) =>
overrideKeys.has(variantKey)
);
const merged = Object.fromEntries(
sharedKeys.map((sharedKey) => [
sharedKey,
{ ...variants[sharedKey], ...overrides[sharedKey] },
])
);
return {
...variants,
...overrides,
...merged,
};
};
const overrides = mergeVariantsAndOverrides(
getOverridesFromVariants(variants, props),
overridesProp || {}
Expand Down Expand Up @@ -1280,6 +1261,7 @@ import {
Variant,
getOverrideProps,
getOverridesFromVariants,
mergeVariantsAndOverrides,
} from \\"@aws-amplify/ui-react/internal\\";
import { Button, Flex, FlexProps, Text } from \\"@aws-amplify/ui-react\\";
Expand Down Expand Up @@ -1525,26 +1507,6 @@ export default function ComplexTest9(
},
},
];
const mergeVariantsAndOverrides = (
variants: EscapeHatchProps,
overrides: EscapeHatchProps
): EscapeHatchProps => {
const overrideKeys = new Set(Object.keys(overrides));
const sharedKeys = Object.keys(variants).filter((variantKey) =>
overrideKeys.has(variantKey)
);
const merged = Object.fromEntries(
sharedKeys.map((sharedKey) => [
sharedKey,
{ ...variants[sharedKey], ...overrides[sharedKey] },
])
);
return {
...variants,
...overrides,
...merged,
};
};
const overrides = mergeVariantsAndOverrides(
getOverridesFromVariants(variants, props),
overridesProp || {}
Expand Down Expand Up @@ -3813,6 +3775,7 @@ import {
Variant,
getOverrideProps,
getOverridesFromVariants,
mergeVariantsAndOverrides,
} from \\"@aws-amplify/ui-react/internal\\";
import { View, ViewProps } from \\"@aws-amplify/ui-react\\";
Expand All @@ -3833,26 +3796,6 @@ export default function ViewPrimitive(
overrides: { View: { label: \\"componentWithVariantsWithLabelProp\\" } },
},
];
const mergeVariantsAndOverrides = (
variants: EscapeHatchProps,
overrides: EscapeHatchProps
): EscapeHatchProps => {
const overrideKeys = new Set(Object.keys(overrides));
const sharedKeys = Object.keys(variants).filter((variantKey) =>
overrideKeys.has(variantKey)
);
const merged = Object.fromEntries(
sharedKeys.map((sharedKey) => [
sharedKey,
{ ...variants[sharedKey], ...overrides[sharedKey] },
])
);
return {
...variants,
...overrides,
...merged,
};
};
const overrides = mergeVariantsAndOverrides(
getOverridesFromVariants(variants, props),
overridesProp || {}
Expand Down Expand Up @@ -3881,6 +3824,7 @@ import {
Variant,
getOverrideProps,
getOverridesFromVariants,
mergeVariantsAndOverrides,
} from \\"@aws-amplify/ui-react/internal\\";
import { Button, ButtonProps } from \\"@aws-amplify/ui-react\\";
Expand Down Expand Up @@ -3913,26 +3857,6 @@ export default function CustomButton(
overrides: { Button: { width: \\"500\\" } },
},
];
const mergeVariantsAndOverrides = (
variants: EscapeHatchProps,
overrides: EscapeHatchProps
): EscapeHatchProps => {
const overrideKeys = new Set(Object.keys(overrides));
const sharedKeys = Object.keys(variants).filter((variantKey) =>
overrideKeys.has(variantKey)
);
const merged = Object.fromEntries(
sharedKeys.map((sharedKey) => [
sharedKey,
{ ...variants[sharedKey], ...overrides[sharedKey] },
])
);
return {
...variants,
...overrides,
...merged,
};
};
const overrides = mergeVariantsAndOverrides(
getOverridesFromVariants(variants, props),
overridesProp || {}
Expand All @@ -3957,6 +3881,7 @@ import {
Variant,
getOverrideProps,
getOverridesFromVariants,
mergeVariantsAndOverrides,
} from \\"@aws-amplify/ui-react/internal\\";
import { Button, ButtonProps } from \\"@aws-amplify/ui-react\\";
Expand Down Expand Up @@ -4004,26 +3929,6 @@ export default function CustomButton(
},
},
];
const mergeVariantsAndOverrides = (
variants: EscapeHatchProps,
overrides: EscapeHatchProps
): EscapeHatchProps => {
const overrideKeys = new Set(Object.keys(overrides));
const sharedKeys = Object.keys(variants).filter((variantKey) =>
overrideKeys.has(variantKey)
);
const merged = Object.fromEntries(
sharedKeys.map((sharedKey) => [
sharedKey,
{ ...variants[sharedKey], ...overrides[sharedKey] },
])
);
return {
...variants,
...overrides,
...merged,
};
};
const overrides = mergeVariantsAndOverrides(
getOverridesFromVariants(variants, props),
overridesProp || {}
Expand Down
2 changes: 2 additions & 0 deletions packages/codegen-ui-react/lib/imports/import-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export enum ImportValue {
CREATE_DATA_STORE_PREDICATE = 'createDataStorePredicate',
USE_DATA_STORE_BINDING = 'useDataStoreBinding',
CREATE_THEME = 'createTheme',
MERGE_VARIANTS_OVERRIDES = 'mergeVariantsAndOverrides',
}

export const ImportMapping: Record<ImportValue, ImportSource> = {
Expand All @@ -44,4 +45,5 @@ export const ImportMapping: Record<ImportValue, ImportSource> = {
[ImportValue.USE_DATA_STORE_BINDING]: ImportSource.UI_REACT_INTERNAL,
[ImportValue.SORT_DIRECTION]: ImportSource.AMPLIFY_DATASTORE,
[ImportValue.SORT_PREDICATE]: ImportSource.AMPLIFY_DATASTORE,
[ImportValue.MERGE_VARIANTS_OVERRIDES]: ImportSource.UI_REACT_INTERNAL,
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class ReactRequiredDependencyProvider extends RequiredDependencyProvider<
return [
{
dependencyName: '@aws-amplify/ui-react',
supportedSemVerPattern: '^2.1.4',
supportedSemVerPattern: '^2.1.5',
reason: 'Required to leverage amplify ui primitives, and studio component helper functions.',
},
];
Expand Down
Loading

0 comments on commit 5b2b838

Please sign in to comment.