diff --git a/src/components/codefield/CodeField.stories.mdx b/src/components/codefield/CodeField.stories.mdx index c34d2ad2..5bbe55c6 100644 --- a/src/components/codefield/CodeField.stories.mdx +++ b/src/components/codefield/CodeField.stories.mdx @@ -48,6 +48,19 @@ export const EditableTemplate = (args) => { > {EditableTemplate.bind({})} + \\`, + displayCopy: true, + height: 200, + }} + parameters={getFigmaParameters( + "https://www.figma.com/file/YjE625ScDMf2ILjWB1sTMc/System?type=design&node-id=223-8049&mode=design&t=P3rN3pHdOl7FkE44-0" + )} + > + {Template.bind({})} + diff --git a/src/components/codefield/CodeField.tsx b/src/components/codefield/CodeField.tsx index d332360d..fac9e0f5 100644 --- a/src/components/codefield/CodeField.tsx +++ b/src/components/codefield/CodeField.tsx @@ -26,6 +26,7 @@ export type CodeFieldProps = { readOnly?: ReactCodeMirrorProps["readOnly"]; onChange?: ReactCodeMirrorProps["onChange"]; size?: CODE_FIELD_SIZE; + height?: number; } & HTMLAttributes; const CodeFieldRenderFunction: ForwardRefRenderFunction = ( @@ -42,6 +43,7 @@ const CodeFieldRenderFunction: ForwardRefRenderFunction {displayCopy && ( ({ ...expandProperty("padding", "24px"), display: "flex", justifyContent: "space-between", - alignItems: "center", + alignItems: "flex-start", flexWrap: "nowrap", gap: "16px", ...expandProperty("transition", "background 0.15s"), @@ -21,14 +21,17 @@ const getContainerStyles = (size: CODE_FIELD_SIZE): StyleObject => ({ fontSize: size === CODE_FIELD_SIZE.small ? "14px" : "16px", }); -const codemirrorStyles: StyleObject = { +const getCodemirrorStyles = (height?: number): StyleObject => ({ minWidth: 0, + height: height ? `${height}px` : "auto", + overflow: height ? "scroll" : "auto", + flexGrow: 1, ":focus-within .cm-editor": { outline: "none", }, -}; +}); export const styles = { getContainerStyles, - codemirrorStyles, + getCodemirrorStyles, };