Skip to content

Commit f1bc522

Browse files
authored
feat(HotKeys): inherit type (#875)
1 parent ae87ec0 commit f1bc522

File tree

6 files changed

+138
-5
lines changed

6 files changed

+138
-5
lines changed

.changeset/hotkeys-inherit-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cube-dev/ui-kit': patch
3+
---
4+
5+
Add `inherit` type to HotKeys component. The inherit type uses `currentColor` for both text and border, allowing the component to adapt to its parent's color context with a transparent background.

.cursor/rules/documentation.mdc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
2-
globs: *.docs.mdx
2+
description: When updating the component documentation file *.docs.mdx
33
alwaysApply: false
44
---
5-
65
# Component Documentation Guidelines
76

87
This guide outlines the standards and structure for documenting components in the Cube UI Kit. Following these guidelines ensures consistency, clarity, and comprehensive coverage of component features.

.cursor/rules/storybook.mdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
globs: *.stories.tsx,*.docs.mdx
2+
description: When updating storybook files and documentatino files *.stories.tsx, *.docs.mdx
33
alwaysApply: false
44
---
55
## Imports

src/components/content/HotKeys/HotKeys.docs.mdx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ Customizes the root element of the component (Space component).
4343

4444
These properties allow direct style application without using the `styles` prop: `width`, `height`, `padding`, `margin`, `gap`, `flow`, `placeContent`, `placeItems`.
4545

46+
#### type
47+
48+
Defines the visual appearance of the keyboard shortcuts.
49+
50+
**Type:** `'default' | 'primary' | 'inherit'`
51+
52+
**Default:** `'default'`
53+
54+
- `default` - Standard appearance with subtle background and border
55+
- `primary` - High contrast appearance with white text and border on transparent background
56+
- `inherit` - Adapts to parent's text color for both text and border, transparent background
57+
4658
### Accessibility Properties
4759

4860
#### label
@@ -67,6 +79,50 @@ The `mods` property accepts standard Space component modifiers.
6779
<HotKeys>mod+k</HotKeys>
6880
```
6981

82+
### Types
83+
84+
The HotKeys component supports different visual types:
85+
86+
#### Default Type
87+
88+
<Story of={HotKeysStories.Default} />
89+
90+
```jsx
91+
<HotKeys>mod+k</HotKeys>
92+
```
93+
94+
#### Primary Type
95+
96+
<Story of={HotKeysStories.Primary} />
97+
98+
```jsx
99+
<HotKeys type="primary" aria-label="Search">mod+k</HotKeys>
100+
```
101+
102+
#### Inherit Type
103+
104+
The `inherit` type uses the current text color for the border and text, making it adapt to its parent's color context.
105+
106+
<Story of={HotKeysStories.Inherit} />
107+
108+
```jsx
109+
<HotKeys type="inherit" aria-label="Search">mod+k</HotKeys>
110+
```
111+
112+
#### Inherit Type in Context
113+
114+
The inherit type is particularly useful when the HotKeys component needs to match the surrounding text color:
115+
116+
<Story of={HotKeysStories.InheritInContext} />
117+
118+
```jsx
119+
<div style={{ color: '#2563eb' }}>
120+
<span>Press </span>
121+
<HotKeys type="inherit" aria-label="Search">mod+k</HotKeys>
122+
<span> to search</span>
123+
</div>
124+
```
125+
70126
### With Accessibility Labels
71127

72128
<Story of={HotKeysStories.SingleKey} />

src/components/content/HotKeys/HotKeys.stories.tsx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ export default {
1515
type: { summary: 'string' },
1616
},
1717
},
18+
type: {
19+
control: {
20+
type: 'select',
21+
},
22+
options: ['default', 'primary', 'inherit'],
23+
description:
24+
'Visual appearance type: default (subtle), primary (high contrast), or inherit (adapts to parent color)',
25+
table: {
26+
type: { summary: "'default' | 'primary' | 'inherit'" },
27+
defaultValue: { summary: 'default' },
28+
},
29+
},
1830
'aria-label': {
1931
control: {
2032
type: 'text',
@@ -118,3 +130,62 @@ WithCustomStyles.args = {
118130
radius: '1r',
119131
},
120132
};
133+
134+
export const Primary: StoryFn<CubeHotKeysProps> = (args) => (
135+
<div style={{ padding: '16px', background: '#1a1a1a', borderRadius: '8px' }}>
136+
<HotKeys {...args} />
137+
</div>
138+
);
139+
Primary.args = {
140+
children: 'mod+k',
141+
type: 'primary',
142+
'aria-label': 'Search',
143+
};
144+
145+
export const Inherit = Template.bind({});
146+
Inherit.args = {
147+
children: 'mod+k',
148+
type: 'inherit',
149+
'aria-label': 'Search',
150+
};
151+
152+
export const InheritInContext: StoryFn<CubeHotKeysProps> = () => (
153+
<div style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}>
154+
<div style={{ color: '#2563eb' }}>
155+
<span>Press </span>
156+
<HotKeys type="inherit" aria-label="Search">
157+
mod+k
158+
</HotKeys>
159+
<span> to search (blue context)</span>
160+
</div>
161+
<div style={{ color: '#dc2626' }}>
162+
<span>Press </span>
163+
<HotKeys type="inherit" aria-label="Delete">
164+
delete
165+
</HotKeys>
166+
<span> to delete (red context)</span>
167+
</div>
168+
<div style={{ color: '#16a34a' }}>
169+
<span>Press </span>
170+
<HotKeys type="inherit" aria-label="Save">
171+
mod+s
172+
</HotKeys>
173+
<span> to save (green context)</span>
174+
</div>
175+
<div style={{ color: '#9333ea' }}>
176+
<span>Press </span>
177+
<HotKeys type="inherit" aria-label="Command palette">
178+
mod+shift+p
179+
</HotKeys>
180+
<span> for commands (purple context)</span>
181+
</div>
182+
</div>
183+
);
184+
InheritInContext.parameters = {
185+
docs: {
186+
description: {
187+
story:
188+
"The inherit type adapts to the parent element's text color, making it perfect for use within colored text contexts.",
189+
},
190+
},
191+
};

src/components/content/HotKeys/HotKeys.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ const KeyElement = tasty({
4242
color: {
4343
'': '#dark.65',
4444
'type=primary': '#white',
45+
'type=inherit': 'currentColor',
4546
},
4647
fill: {
4748
'': '#dark.04',
48-
'type=primary': '#clear',
49+
'type=primary | type=inherit': '#clear',
4950
},
5051
border: {
5152
'': true,
5253
'type=primary': '#white',
54+
'type=inherit': 'currentColor',
5355
},
5456
},
5557
});
@@ -58,7 +60,7 @@ export interface CubeHotKeysProps
5860
extends BasePropsWithoutChildren,
5961
ContainerStyleProps {
6062
children: string;
61-
type?: 'default' | 'primary';
63+
type?: 'default' | 'primary' | 'inherit';
6264
}
6365

6466
function HotKeys(props: CubeHotKeysProps, ref) {

0 commit comments

Comments
 (0)