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

TS example #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,32 @@ const Button = styled.button`

The same can be done when you `applyResponsiveStyleModifiers` _(deprecated)_.

## TypeScript example

```ts
import styled from "styled-components"
import { applyStyleModifiers, WithModifiers, ModifiersConfig } from "styled-components-modifiers"

// Example of modifiers with typing
const MODAL_MODIFIERS: ModifiersConfig = {}

// Example of a styled component optionally accepting "modifiers" prop
const MyStyledWrapper = styled.div<WithModifiers>`
max-width: 800px;
${applyStyleModifiers(MODAL_MODIFIERS)}
`;

// Example of a custom component optionally accepting modifiers
interface MyComponentProps extends WithModifiers {
children: React.ReactNode;
}

// Will be typed as expected
export const MyComponent = ({ children, modifiers }: MyComponentProps) => (
<MyStyledWrapper modifiers={modifiers}>{children}</MyStyledWrapper>
);
```

## Built with Styled Components Modifiers

Here's your chance to showcase work you are proud of! Feel free to add a link to
Expand Down