-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ShortcutTag component with customizable props and stories
- Loading branch information
Showing
4 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { ShortcutTag } from "."; | ||
|
||
const meta = { | ||
title: "Atoms/ShortcutTag", | ||
component: ShortcutTag, | ||
|
||
parameters: { | ||
layout: "centered", | ||
}, | ||
args: {}, | ||
} satisfies Meta<typeof ShortcutTag>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
text: "Space", | ||
}, | ||
}; | ||
|
||
export const Ctrl: Story = { | ||
args: { | ||
ctrl: true, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
import { isMac } from "../theme/utils"; | ||
import { SM } from "../typography/typescale"; | ||
import { ReactComponent as CmdIcon } from "./assets/cmd.svg"; | ||
|
||
const ShortcutTagWrapper = styled.div` | ||
padding: 10px; | ||
border-radius: 4px; | ||
background-color: ${({ theme }) => theme.palette.blue[100]}; | ||
color: ${({ theme }) => theme.palette.grey[700]}; | ||
cursor: default; | ||
user-select: none; | ||
${SM} { | ||
display: flex; | ||
} | ||
`; | ||
|
||
type ShortcutContent = | ||
| { text: React.ReactNode; ctrl?: never } | ||
| { ctrl: true; text?: never }; | ||
|
||
export type ShortcutTagProps = ShortcutContent & | ||
React.HTMLAttributes<HTMLDivElement>; | ||
|
||
const ShortcutTag = (props: ShortcutTagProps) => { | ||
return ( | ||
<ShortcutTagWrapper {...props}> | ||
<SM isBold> | ||
{props.ctrl ? !isMac() ? <CmdIcon width={16} /> : "Ctrl" : null} | ||
{props.text ? props.text : null} | ||
</SM> | ||
</ShortcutTagWrapper> | ||
); | ||
}; | ||
|
||
export { ShortcutTag }; |