diff --git a/packages/canon/src/components/Heading/Heading.stories.tsx b/packages/canon/src/components/Heading/Heading.stories.tsx new file mode 100644 index 0000000000..d93c7dbb59 --- /dev/null +++ b/packages/canon/src/components/Heading/Heading.stories.tsx @@ -0,0 +1,42 @@ +/* + * 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 type { Meta, StoryObj } from '@storybook/react'; +import { Heading } from './Heading'; + +const meta = { + title: 'Components/Heading', + component: Heading, +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +export const Default: Story = { + args: { + children: 'Heading', + }, +}; + +export const Responsive: Story = { + args: { + ...Default.args, + variant: { + // xs: 'title4', + sm: 'display', + }, + }, +}; diff --git a/packages/canon/src/components/Heading/Heading.tsx b/packages/canon/src/components/Heading/Heading.tsx new file mode 100644 index 0000000000..86a2fc39ee --- /dev/null +++ b/packages/canon/src/components/Heading/Heading.tsx @@ -0,0 +1,45 @@ +/* + * 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 { HeadingProps } from './types'; +import { useTheme } from '../../theme/context'; +import { getResponsiveValue } from '../../utils/getResponsiveValue'; + +export const Heading = forwardRef( + (props, ref) => { + const { children, variant = 'title1', ...restProps } = props; + const { breakpoint } = useTheme(); + const responsiveVariant = getResponsiveValue(variant, breakpoint); + + console.log(breakpoint); + console.log(responsiveVariant); + + return ( +

+ {children} +

+ ); + }, +); + +Heading.displayName = 'Heading'; diff --git a/packages/canon/src/components/Heading/index.ts b/packages/canon/src/components/Heading/index.ts new file mode 100644 index 0000000000..69b7c3c1a0 --- /dev/null +++ b/packages/canon/src/components/Heading/index.ts @@ -0,0 +1,18 @@ +/* + * 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 { Heading } from './Heading'; +export type { HeadingProps } from './types'; diff --git a/packages/canon/src/components/Heading/styles.css b/packages/canon/src/components/Heading/styles.css new file mode 100644 index 0000000000..e6e26bb06e --- /dev/null +++ b/packages/canon/src/components/Heading/styles.css @@ -0,0 +1,57 @@ +/* + * 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. + */ + +.text { + font-family: var(--canon-font-regular); + padding: 0; + margin: 0; + + &.text-display { + font-size: var(--canon-font-size-display); + line-height: 100%; + font-weight: var(--canon-font-bold); + } + + &.text-title1 { + font-size: var(--canon-font-size-title1); + line-height: 100%; + font-weight: var(--canon-font-bold); + } + + &.text-title2 { + font-size: var(--canon-font-size-title2); + line-height: 100%; + font-weight: var(--canon-font-bold); + } + + &.text-title3 { + font-size: var(--canon-font-size-title3); + line-height: 100%; + font-weight: var(--canon-font-bold); + } + + &.text-title4 { + font-size: var(--canon-font-size-title4); + line-height: 100%; + font-weight: var(--canon-font-bold); + } + + &.text-title5 { + font-size: var(--canon-font-size-title5); + line-height: 100%; + font-weight: var(--canon-font-bold); + } +} diff --git a/packages/canon/src/components/Heading/types.ts b/packages/canon/src/components/Heading/types.ts new file mode 100644 index 0000000000..86145e5738 --- /dev/null +++ b/packages/canon/src/components/Heading/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 { Breakpoint } from '../../layout/types'; + +/** @public */ +export interface HeadingProps { + children: React.ReactNode; + variant?: + | 'display' + | 'title1' + | 'title2' + | 'title3' + | 'title4' + | 'title5' + | Partial< + Record< + Breakpoint, + 'display' | 'title1' | 'title2' | 'title3' | 'title4' | 'title5' + > + >; +}