|
@@ -1,25 +1,40 @@
|
|
|
import {type ElementType} from 'react';
|
|
|
import styled from '@emotion/styled';
|
|
|
+import first from 'lodash/first';
|
|
|
|
|
|
import JSXProperty from 'sentry/components/stories/jsxProperty';
|
|
|
-import SizingWindow from 'sentry/components/stories/sizingWindow';
|
|
|
+import SizingWindow, {
|
|
|
+ Props as SizingWindowProps,
|
|
|
+} from 'sentry/components/stories/sizingWindow';
|
|
|
import {space} from 'sentry/styles/space';
|
|
|
|
|
|
-interface Props {
|
|
|
- component: ElementType;
|
|
|
- propMatrix: Record<string, unknown[]>;
|
|
|
- selectedProps: [string, string];
|
|
|
+type RenderProps = {};
|
|
|
+
|
|
|
+export type PropMatrix<P extends RenderProps> = Partial<{
|
|
|
+ [Prop in keyof P]: P[Prop][];
|
|
|
+}>;
|
|
|
+
|
|
|
+interface Props<P extends RenderProps> {
|
|
|
+ propMatrix: PropMatrix<P>;
|
|
|
+ render: ElementType<P>;
|
|
|
+ selectedProps: [keyof P, keyof P];
|
|
|
+ sizingWindowProps?: SizingWindowProps;
|
|
|
}
|
|
|
|
|
|
-export default function Matrix({component, propMatrix, selectedProps}: Props) {
|
|
|
+export default function Matrix<P extends RenderProps>({
|
|
|
+ propMatrix,
|
|
|
+ render,
|
|
|
+ selectedProps,
|
|
|
+ sizingWindowProps,
|
|
|
+}: Props<P>) {
|
|
|
const defaultValues = Object.fromEntries(
|
|
|
Object.entries(propMatrix).map(([key, values]) => {
|
|
|
- return [key, values[0]];
|
|
|
+ return [key, first(values as any)];
|
|
|
})
|
|
|
);
|
|
|
|
|
|
- const values1 = propMatrix[selectedProps[0]];
|
|
|
- const values2 = propMatrix[selectedProps[1]];
|
|
|
+ const values1 = propMatrix[selectedProps[0]] ?? [];
|
|
|
+ const values2 = propMatrix[selectedProps[1]] ?? [];
|
|
|
|
|
|
const items = values1.flatMap(value1 => {
|
|
|
const label = (
|
|
@@ -28,11 +43,15 @@ export default function Matrix({component, propMatrix, selectedProps}: Props) {
|
|
|
</div>
|
|
|
);
|
|
|
const content = values2.map(value2 => {
|
|
|
- return item(component, {
|
|
|
- ...defaultValues,
|
|
|
- [selectedProps[0]]: value1,
|
|
|
- [selectedProps[1]]: value2,
|
|
|
- });
|
|
|
+ return item(
|
|
|
+ render,
|
|
|
+ {
|
|
|
+ ...defaultValues,
|
|
|
+ [selectedProps[0]]: value1,
|
|
|
+ [selectedProps[1]]: value2,
|
|
|
+ },
|
|
|
+ sizingWindowProps
|
|
|
+ );
|
|
|
});
|
|
|
return [label, ...content];
|
|
|
});
|
|
@@ -59,15 +78,15 @@ export default function Matrix({component, propMatrix, selectedProps}: Props) {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
-function item(Component, props) {
|
|
|
+function item(Component, props, sizingWindowProps) {
|
|
|
const hasChildren = 'children' in props;
|
|
|
|
|
|
return hasChildren ? (
|
|
|
- <SizingWindow key={JSON.stringify(props)}>
|
|
|
+ <SizingWindow key={JSON.stringify(props)} {...sizingWindowProps}>
|
|
|
<Component {...props}>{props.children}</Component>
|
|
|
</SizingWindow>
|
|
|
) : (
|
|
|
- <SizingWindow key={JSON.stringify(props)}>
|
|
|
+ <SizingWindow key={JSON.stringify(props)} {...sizingWindowProps}>
|
|
|
<Component {...props} />
|
|
|
</SizingWindow>
|
|
|
);
|