Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UNSAFE classname test #1826

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/web-react/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ const _Button = <T extends ElementType = 'button', C = void, S = void>(

const Button = forwardRef<HTMLButtonElement, SpiritButtonProps<ElementType>>(_Button);

Button.isSystemComponent = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I think, we will use something like Button.spiritComponent = Button for cases where we want to check if it is a Spirit component or if we want a name.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can use Button.isSpiritComponent first and reimplement it when needed.


export default Button;
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ const TooltipTrigger = (props: TooltipTriggerProps) => {
id={id}
ref={triggerRef}
{...getReferenceProps()}
{...(typeof ElementTag !== 'string' && { useUnsafe: typeof ElementTag === 'string' })}
// {...(typeof ElementTag !== 'string' && { useUnsafe: typeof ElementTag === 'string' })}
>
{typeof children === 'function' ? children({ isOpen }) : children}
</ElementTag>
);
};

TooltipTrigger.isSystemComponent = true;

export default TooltipTrigger;
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const TooltipDefault = () => {
const [open, setOpen] = useState(true);

const OutsideComponent = (props: any) => {
return <p {...props}>{props.children}</p>;
return <button {...props}>{props.children}</button>;
};

return (
<Tooltip id="tooltip-default" isOpen={open} onToggle={setOpen}>
{/* <TooltipTrigger elementType="button" UNSAFE_className="unsafe"> */}
<TooltipTrigger elementType={OutsideComponent} className="unsafe">
<TooltipTrigger elementType={Button} UNSAFE_className="unsafe">
I have a tooltip 😎
</TooltipTrigger>
<TooltipPopover>Hello there!</TooltipPopover>
Expand Down
18 changes: 4 additions & 14 deletions packages/web-react/src/hooks/styleProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ export type StylePropsResult = {

export function useStyleProps<T extends StyleProps>(props: T): StylePropsResult {
const classNamePrefix = useContext(ClassNamePrefixContext);
const { UNSAFE_className, UNSAFE_style, ElementTag, useUnsafe: receivedUseUnsafe, ...otherProps } = props;
const { UNSAFE_className, UNSAFE_style, ElementTag, ...otherProps } = props;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I think we should pass here only the bool value and not the entire ElementTag/Component.

const { styleUtilities, props: modifiedProps } = useStyleUtilities(otherProps, classNamePrefix);

console.log('ElementTag:', ElementTag, receivedUseUnsafe);

const style: CSSProperties = { ...UNSAFE_style };

// console.log('typeof ElementTag:', typeof ElementTag);
// if (typeof ElementTag === 'string' && receivedUseUnsafe == null) {
if (typeof ElementTag === 'string' && !receivedUseUnsafe) {
// @ts-ignore
if (typeof ElementTag === 'string' || !ElementTag?.isSystemComponent) {
// Want to check if className prop exists, but not to define it in StyleProps type
// @ts-expect-error Property 'className' does not exist on type 'Omit<T, "UNSAFE_className" | "UNSAFE_style">'.
if (modifiedProps.className) {
Expand Down Expand Up @@ -62,21 +59,14 @@ export function useStyleProps<T extends StyleProps>(props: T): StylePropsResult

return {
styleProps,
props: { ...(modifiedProps as HTMLAttributes<HTMLElement>), props1: 'test' },
props: { ...(modifiedProps as HTMLAttributes<HTMLElement>) },
};
}

const rimmerProps = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Please, remove this.

...modifiedProps,
props2: 'test',
};

if (receivedUseUnsafe === false) {
rimmerProps.useUnsafe = true;
} else if (receivedUseUnsafe === true) {
rimmerProps.useUnsafe = undefined;
}

return {
styleProps: {
...(UNSAFE_style !== undefined && { UNSAFE_style }),
Expand Down
Loading