diff --git a/packages/canon/docs/Home.mdx b/packages/canon/docs/Home.mdx index cbe84fcfb1..5b85ab15ad 100644 --- a/packages/canon/docs/Home.mdx +++ b/packages/canon/docs/Home.mdx @@ -50,7 +50,7 @@ import { list } from './components/Roadmap/list'; ; + +export default meta; +type Story = StoryObj; + +const FakeBox = () => ( + +); + +export const Default: Story = { + args: {}, + render: args => ( + + + + ), +}; diff --git a/packages/canon/src/components/Container/Container.tsx b/packages/canon/src/components/Container/Container.tsx new file mode 100644 index 0000000000..b27775e116 --- /dev/null +++ b/packages/canon/src/components/Container/Container.tsx @@ -0,0 +1,37 @@ +/* + * Copyright 2024 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React, { forwardRef } from 'react'; +import { containerSprinkles } from './sprinkles.css'; +import { ContainerProps } from './types'; + +/** @public */ +export const Container = forwardRef( + (props, ref) => { + const { children, className, style, ...restProps } = props; + + const containerClassName = containerSprinkles(restProps); + + return ( +
+ {children} +
+ ); + }, +); diff --git a/packages/canon/src/components/Container/Docs.mdx b/packages/canon/src/components/Container/Docs.mdx new file mode 100644 index 0000000000..68090dac3e --- /dev/null +++ b/packages/canon/src/components/Container/Docs.mdx @@ -0,0 +1,74 @@ +import { Meta, Unstyled, Source } from '@storybook/blocks'; +import * as ContainerStories from './Container.stories'; +import { Title, Text } from '../../../docs/components'; +import { PropsTable, getBoxProps } from '../../../docs/components/PropsTable'; +import { spacingProperties } from '../../layout/sprinkles.css'; +import { containerProperties } from './sprinkles.css'; + + + + + +Container + + + The container component let you use our default max-width and center the + content on the page. + + +Installation + + + + API reference + + + + +Examples + +Simple +A simple example of how to use the Container component. + + + Hello World + Hello World + Hello World +`} + language="tsx" + dark +/> + +Responsive padding & margin + + The Container component also supports responsive values, making it easy to + create responsive designs. + + + Hello World + Hello World + Hello World +`} + language="tsx" + dark +/> + + diff --git a/packages/canon/src/components/Container/index.tsx b/packages/canon/src/components/Container/index.tsx new file mode 100644 index 0000000000..81614c352d --- /dev/null +++ b/packages/canon/src/components/Container/index.tsx @@ -0,0 +1,17 @@ +/* + * Copyright 2024 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export { Container } from './Container'; +export type { ContainerProps } from './types'; diff --git a/packages/canon/src/components/Container/sprinkles.css.ts b/packages/canon/src/components/Container/sprinkles.css.ts new file mode 100644 index 0000000000..989e369433 --- /dev/null +++ b/packages/canon/src/components/Container/sprinkles.css.ts @@ -0,0 +1,40 @@ +/* + * Copyright 2024 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { defineProperties, createSprinkles } from '@vanilla-extract/sprinkles'; +import { breakpoints, space } from '../../layout/properties'; +import { colorProperties, spacingProperties } from '../../layout/sprinkles.css'; + +export const containerProperties = defineProperties({ + conditions: breakpoints, + defaultCondition: 'xs', + properties: { + paddingTop: space, + paddingBottom: space, + marginTop: space, + marginBottom: space, + }, + shorthands: { + paddingY: ['paddingTop', 'paddingBottom'], + marginY: ['marginTop', 'marginBottom'], + }, +}); + +export const containerSprinkles = createSprinkles( + spacingProperties, + colorProperties, + containerProperties, +); diff --git a/packages/canon/src/components/Container/styles.css b/packages/canon/src/components/Container/styles.css new file mode 100644 index 0000000000..4da813623f --- /dev/null +++ b/packages/canon/src/components/Container/styles.css @@ -0,0 +1,5 @@ +.container { + max-width: var(--canon-container-max-width); + margin: 0 auto; + padding: 0 var(--canon-container-padding); +} diff --git a/packages/canon/src/components/Container/types.ts b/packages/canon/src/components/Container/types.ts new file mode 100644 index 0000000000..b1f414cf30 --- /dev/null +++ b/packages/canon/src/components/Container/types.ts @@ -0,0 +1,35 @@ +/* + * Copyright 2024 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { SpaceProps } from '../../layout/types'; + +/** @public */ +export interface ContainerProps + extends Omit< + SpaceProps, + | 'padding' + | 'paddingLeft' + | 'paddingRight' + | 'paddingX' + | 'margin' + | 'marginLeft' + | 'marginRight' + | 'marginX' + | 'gap' + > { + children?: React.ReactNode; + className?: string; + style?: React.CSSProperties; +} diff --git a/packages/canon/src/theme/styles.css b/packages/canon/src/theme/styles.css index 65aaabe909..ad2433ef74 100644 --- a/packages/canon/src/theme/styles.css +++ b/packages/canon/src/theme/styles.css @@ -26,3 +26,4 @@ @import '../components/Stack/styles.css'; @import '../components/Inline/styles.css'; @import '../components/Grid/styles.css'; +@import '../components/Container/styles.css'; diff --git a/packages/canon/src/theme/theme.css b/packages/canon/src/theme/theme.css index 6784cb336f..ef78b2221a 100644 --- a/packages/canon/src/theme/theme.css +++ b/packages/canon/src/theme/theme.css @@ -74,6 +74,10 @@ --canon-spacing-lg: 2rem; --canon-spacing-xl: 3.25rem; --canon-spacing-2xl: 5.25rem; + + /* Container */ + --canon-container-max-width: 1200px; + --canon-container-padding: 1rem; } /* Dark theme */