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

Exist a way to generate the style object or classNames to be used in other third party libraries? #410

Open
ChristianHardy opened this issue Sep 5, 2023 · 0 comments

Comments

@ChristianHardy
Copy link

ChristianHardy commented Sep 5, 2023

💬 Questions and Help

Hello, and thanks for advance.

I'm currently working with GatsbyJS, Gatsby have their own Link component and only can be customized via styles properties or classNames.

So I create an Wrap to encapsulate the Link component (AKA XLink component), I want to receive the common Xstyled props to generate later an style properties, here is an Example to help understanding my doubt.

import { Link } from 'gatsby';
import {
    SpaceProps,
    TypographyProps,
} from '@xstyled/styled-components';

export type XLinkProps = SpaceProps & TypographyProps & {
    children?: React.ReactNode;

    // Gatsby Link props
    to: string;
    activeClassName?: string;
    activeStyle?: React.CSSProperties;
    partiallyActive?: boolean;
};

function XLink(props: XLinkProps) {
    const { to, activeClassName, activeStyle, partiallyActive, ...xstyledProps } = props;

    // Something magic here to generate style object based on xstyled props
    const style = someFunctionToGenerateCSSStyles(xstyledProps);
    const className = someFunctionToGenerateClassNames(xstyledProps);

    return (
        <Link to={to} style={style} className={className}>
            { children }
        </Link>
    );
}

export { XLink };

// Usage example
<XLink to="/about" color="primary" mx={{_: 2, md: 5}}>About</XLink>
@ChristianHardy ChristianHardy changed the title Exist a way to generate the style object to be used in other third party libraries? Exist a way to generate the style object or classNames to be used in other third party libraries? Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant