diff --git a/frontend/src/components/OAuth2Session.tsx b/frontend/src/components/OAuth2Session.tsx index 82c8270d6..98577137e 100644 --- a/frontend/src/components/OAuth2Session.tsx +++ b/frontend/src/components/OAuth2Session.tsx @@ -14,6 +14,7 @@ import type { OAuth2Session_session$key } from "./__generated__/OAuth2Session_session.graphql"; import { graphql, useFragment } from "react-relay"; +import Typography, { Bold, Code } from "./Typography"; type Props = { session: OAuth2Session_session$key; @@ -39,18 +40,18 @@ const OAuth2Session: React.FC = ({ session }) => { return (
- Client ID:{" "} - {data.client.clientId} + + Client ID: {data.scope} +
{data.client.clientName && ( -
- Client name:{" "} - {data.client.clientName} -
+ + Client name: {data.client.clientName} + )} -
- Scope: {data.scope} -
+ + Scope: {data.scope} +
); }; diff --git a/frontend/src/components/Typography.stories.tsx b/frontend/src/components/Typography.stories.tsx new file mode 100644 index 000000000..a6b37c9cb --- /dev/null +++ b/frontend/src/components/Typography.stories.tsx @@ -0,0 +1,110 @@ +// Copyright 2022 The Matrix.org Foundation C.I.C. +// +// 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 Typography from "./Typography"; + +const meta: Meta = { + title: "UI/Typography", + component: Typography, + tags: ["docsPage"], + args: { + children: "Typography", + }, +}; + +export default meta; +type Story = StoryObj; + +export const Basic: Story = { + args: { + children: "Hello", + variant: "body", + }, +}; + +export const Headline: Story = { + args: { + children: "Headline", + variant: "headline", + }, +}; + +export const Title: Story = { + args: { + children: "Title", + variant: "title", + }, +}; + +export const Subtitle: Story = { + args: { + children: "Subtitle", + variant: "subtitle", + }, +}; + +export const SubtitleSemiBold: Story = { + args: { + children: "Subtitle Semi Bold", + variant: "subtitle", + bold: true, + }, +}; + +export const Body: Story = { + args: { + children: "Body", + variant: "body", + }, +}; + +export const BodySemiBold: Story = { + args: { + children: "Body", + variant: "body", + bold: true, + }, +}; + +export const Caption: Story = { + args: { + children: "Caption", + variant: "caption", + }, +}; + +export const CaptionSemiBold: Story = { + args: { + children: "Caption", + variant: "caption", + bold: true, + }, +}; + +export const Micro: Story = { + args: { + children: "Micro", + variant: "caption", + }, +}; + +export const MicroSemiBold: Story = { + args: { + children: "Micro", + variant: "caption", + bold: true, + }, +}; diff --git a/frontend/src/components/Typography.tsx b/frontend/src/components/Typography.tsx new file mode 100644 index 000000000..9647b9578 --- /dev/null +++ b/frontend/src/components/Typography.tsx @@ -0,0 +1,58 @@ +// Copyright 2022 The Matrix.org Foundation C.I.C. +// +// 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 { createElement, Children } from "react"; + +type Variant = "headline" | "title" | "subtitle" | "body" | "caption" | "micro"; + +type Props = { + children: React.ReactNode; + variant: Variant; + bold?: boolean; +}; + +const elementMap: Record = { + headline: "h1", + title: "h2", + subtitle: "h3", + body: "p", + caption: "p", + micro: "small", +}; + +const classMap: Record = { + headline: "text-3xl font-semibold", + title: "text-2xl font-semibold", + subtitle: "text-lg", + body: "text-base", + caption: "text-sm", + micro: "text-xs", +}; + +const Typography: React.FC = ({ variant, children, bold }) => { + const element = elementMap[variant]; + const boldClass = bold ? "font-semibold" : ""; + const className = `text-black dark:text-white ${boldClass} ${classMap[variant]}`; + return createElement(element, { className }, ...Children.toArray(children)); +}; + +export const Bold: React.FC<{ children: React.ReactNode }> = ({ children }) => ( + {children} +); + +export const Code: React.FC<{ children: React.ReactNode }> = ({ children }) => ( + {children} +); + +export default Typography; diff --git a/frontend/src/pages/Home.tsx b/frontend/src/pages/Home.tsx index 0a1f795f5..7f449f219 100644 --- a/frontend/src/pages/Home.tsx +++ b/frontend/src/pages/Home.tsx @@ -17,6 +17,7 @@ import BrowserSessionList from "../components/BrowserSessionList"; import CompatSsoLoginList from "../components/CompatSsoLoginList"; import OAuth2SessionList from "../components/OAuth2SessionList"; +import Typography from "../components/Typography"; import type { HomeQuery } from "./__generated__/HomeQuery.graphql"; const Home: React.FC = () => { @@ -45,7 +46,7 @@ const Home: React.FC = () => { return ( <> -

Hello {user.username}!

+ Hello {user.username}!