Skip to content

Commit a080e81

Browse files
committed
code review
1 parent 279af73 commit a080e81

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

packages/circuit-ui/components/ActionMenu/ActionMenu.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ An ActionMenu displays a list of subsequent actions, when interacting with an ac
1010
<Story of={Stories.Base} />
1111
<Props />
1212

13-
- The reference element, which triggers ActionMenu, can be primary, secondary, tertiary buttons, an overflow icon, or components with embedded buttons such as the [ImageInput](Forms/ImageInput) component.
14-
- Each ActionMenu action item is represented by an appropriate HTML element (e.g., a button element or an anchor element).
13+
- The reference element which triggers the ActionMenu must be a `button` element or a component that renders a `button` such as the Button or IconButton components.
14+
- Each ActionMenu action item is represented by an appropriate HTML element. Elements provided with an `href` will render as anchor elements while elements provided with an `onClick` will render as buttons.
1515
- If needed, the dividing line can be used to separate ActionMenu action items.
1616
- The leading icon is optional.
17-
- The ActionMenu is powered by [Floating UI](https://floating-ui.com/docs/react-dom). You can easily change the position of the ActionMenu relative to the reference element by passing in the `placement` prop. If you want to offset the ActionMenu in the x and y directions, use the `offset` prop.
17+
- The ActionMenu is powered by [Floating UI](https://floating-ui.com/docs/react-dom). You can change the position of the ActionMenu relative to the reference element by passing in the `placement` prop. If you want to offset the ActionMenu in the x and y directions, use the `offset` prop.
1818

1919
<Story of={Stories.Offset} />
2020

2121
## Related components
2222

23-
This component is built on top of the low level [Popover](Components/Popover/Docs) component. If this component does not meet your requirements, you can use the Dialog component directly to build your own custom popover component.
23+
This component is built on top of the low level [Dialog](Components/Dialog/Docs) component. If this component does not meet your requirements, you can use the Dialog component directly to build your own custom popover component.
2424

2525
## Usage guidelines
2626

27-
- **Do** use clear, concise and actionable labels for ActionMenu items
28-
- **Do** always think about the priority of the action option to be taken and put the option order in logical order
27+
- **Do** use clear, concise and actionable labels for ActionMenu items.
28+
- **Do** always think about the priority of the actions to be taken and put the options in logical order.

packages/eslint-plugin-circuit-ui/no-renamed-components/index.spec.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,24 @@ ruleTester.run('no-renamed-components', noRenamedComponents, {
5757
return <Popover />
5858
}`,
5959
output: `
60-
import {Popover} from '@sumup-oss/circuit-ui';
60+
import {ActionMenu} from '@sumup-oss/circuit-ui';
6161
function Component() {
6262
return <ActionMenu />
6363
}`,
64+
errors: [{ messageId: 'renamed' }, { messageId: 'renamed' }],
65+
},
66+
{
67+
name: 'matched renamed import from Circuit UI',
68+
code: `
69+
import {Popover as CircuitPopover} from '@sumup-oss/circuit-ui';
70+
function Component() {
71+
return <CircuitPopover />
72+
}`,
73+
output: `
74+
import {ActionMenu as CircuitPopover} from '@sumup-oss/circuit-ui';
75+
function Component() {
76+
return <CircuitPopover />
77+
}`,
6478
errors: [{ messageId: 'renamed' }],
6579
},
6680
],

packages/eslint-plugin-circuit-ui/no-renamed-components/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,33 @@ export const noRenamedComponents = createRule({
5252
node.specifiers.forEach((specifier) => {
5353
if (specifier.type === 'ImportSpecifier') {
5454
trackedImports.set(specifier.local.name, node.source.value);
55+
const renamedComponent = components.find(
56+
(comp) =>
57+
comp.name === specifier.local.name ||
58+
comp.name === specifier.imported.name,
59+
);
60+
if (!renamedComponent) {
61+
return;
62+
}
63+
context.report({
64+
node,
65+
messageId: 'renamed',
66+
data: {
67+
name: renamedComponent?.name,
68+
alternative: renamedComponent?.alternative,
69+
},
70+
fix(fixer) {
71+
return fixer.replaceText(
72+
node,
73+
context.sourceCode
74+
.getText(node)
75+
.replace(
76+
renamedComponent?.name,
77+
renamedComponent?.alternative,
78+
),
79+
);
80+
},
81+
});
5582
}
5683
});
5784
}

0 commit comments

Comments
 (0)