Skip to content

Commit 019c5cd

Browse files
authored
chore: Update base-component handling (#25)
1 parent 577297e commit 019c5cd

File tree

5 files changed

+13
-35
lines changed

5 files changed

+13
-35
lines changed

scripts/test-utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,5 @@ function generateIndexFileContent({ testUtilType, buildFinderInterface }) {
8181

8282
function compileTypescript() {
8383
const config = path.resolve("src/test-utils/tsconfig.json");
84-
execaSync("tsc", ["-p", config, "--sourceMap"], { stdio: "inherit" });
84+
execaSync("tsc", ["-p", config, "--sourceMap", "--inlineSources"], { stdio: "inherit" });
8585
}

src/__tests__/base-props-support.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ describe(`base props support for code-view`, async () => {
1919
expect(container.firstElementChild).toHaveAttribute("data-testid", "example");
2020
});
2121

22-
test("should allow id", () => {
22+
test("should not allow id", () => {
2323
const { container } = renderComponent(<Component {...props} id="example" />);
24-
expect(container.querySelector("#example")).not.toBeNull();
24+
expect(container.querySelector("#example")).toBeNull();
2525
});
2626

2727
test("should not allow className", () => {

src/internal/base-component/get-data-attributes.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/internal/base-component/use-base-component.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,18 @@ export default function useBaseComponent<T = any>(componentName: string, config?
2727
return { __internalRootRef: elementRef };
2828
}
2929

30-
export interface BaseComponentProps {
31-
/**
32-
* Adds the specified classes to the root element of the component.
33-
* @deprecated Custom CSS is not supported. For other use cases, use [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes).
34-
*/
35-
className?: string;
36-
/**
37-
* Adds the specified ID to the root element of the component.
38-
* @deprecated Custom CSS is not supported. For other use cases, use [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes).
39-
*/
40-
id?: string;
41-
// we also support data-* attributes, but they are always implicitly allowed by typescript
42-
// http://www.typescriptlang.org/docs/handbook/jsx.html#attribute-type-checking
43-
// "Note: If an attribute name is not a valid JS identifier (like a data-* attribute), it is not considered to be an error"
44-
}
30+
// we also support data-* attributes, but they are always implicitly allowed by typescript
31+
// http://www.typescriptlang.org/docs/handbook/jsx.html#attribute-type-checking
32+
// "Note: If an attribute name is not a valid JS identifier (like a data-* attribute), it is not considered to be an error"
33+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
34+
export interface BaseComponentProps {}
4535

4636
export function getBaseProps(props: BaseComponentProps) {
47-
const baseProps: Record<string, any> = {};
37+
const baseProps: Record<string, string> = {};
4838
Object.keys(props).forEach((prop) => {
49-
if (prop === "id" || prop.match(/^data-/)) {
50-
baseProps[prop] = (props as Record<string, any>)[prop];
39+
if (prop.startsWith("data-")) {
40+
baseProps[prop] = (props as Record<string, string>)[prop];
5141
}
5242
});
53-
return baseProps as BaseComponentProps;
43+
return baseProps;
5444
}

vite.unit.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default defineConfig({
1717
enabled: process.env.CI === "true",
1818
provider: "istanbul",
1919
include: ["src/**", "lib/components/**"],
20-
exclude: ["**/debug-tools/**", "**/__tests__/**", "**/*.d.ts"],
20+
exclude: ["**/__tests__/**", "**/*.d.ts", "**/api-docs/**", "**/test-utils/selectors/**"],
2121
},
2222
},
2323
});

0 commit comments

Comments
 (0)