Skip to content

Commit

Permalink
feat: add ShortcutTag component with customizable props and stories
Browse files Browse the repository at this point in the history
  • Loading branch information
d-beezee committed Nov 21, 2024
1 parent 0fbec8b commit 1b5020a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ export * from "./stories/slider";
// --- Stepper ---
export * from "./stories/stepper";

// --- Shortcut Tag ---
export * from "./stories/shortcut-tag";

// --- Table ---
export {
Caption,
Expand All @@ -168,7 +171,7 @@ export {
Row as TableRow,
} from "./stories/table";

export { GroupRow, GroupedTable } from "./stories/table/grouped";
export { GroupedTable, GroupRow } from "./stories/table/grouped";

// --- Tabs ---
export * from "./stories/tabs";
Expand Down
3 changes: 3 additions & 0 deletions src/stories/shortcut-tag/assets/cmd.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions src/stories/shortcut-tag/index.stories.tsx
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,
},
};
37 changes: 37 additions & 0 deletions src/stories/shortcut-tag/index.tsx
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 };

0 comments on commit 1b5020a

Please sign in to comment.