styled-components-ts
TypeScript icon, indicating that this package has built-in type declarations

0.0.15 • Public • Published
styled-components

CircleCI

Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress and the added benefits of TypeScript 💅

npm install --save styled-components styled-components-ts

Getting Started

// Import react, styledComponents and styledComponentsTS
import * as React from 'react'
import styledComponents from 'styled-components'
import styledComponentsTS from 'styled-components-ts'
 
// Create an interface for the component
export interface MyImageProps {
  size: number
  borderColor?: string
  borderSize?: number
}
 
// Create a styled component with our props interface
const MyImage = styledComponentsTS<MyImageProps>(styledComponents.img) `
  width: ${props => props.size}px;
  height: ${props => props.size}px;
  border: ${props => props.borderSize || '4px'} solid ${props => props.borderColor || 'black'}
`
 
export default MyImage
 

Now we have all the typescript goodies for MyImage like type checking and auto-complete.

import MyImage from './MyImage'
 
<MyImage size={300} borderColor="blue" borderSize={10} />

We can also extend our components and add new props with ease.

// Import react, styledComponents and styledComponentsTS
import * as React from 'react'
import styledComponents from 'styled-components'
import styledComponentsTS from 'styled-components-ts'
 
// Import our image and it's props
import MyImage, { MyImageProps } from './MyImage'
 
// Create an interface for the component that extends the base image props
export interface ExpandedImageProps extends MyImageProps {
  backgroundColor?: string
}
 
// Create a styled component with our props interface that extends MyImage
const ExpandedImage = styledComponentsTS<ExpandedImageProps>(MyImage.extend)`
  background-color: ${props => props.backgroundColor || 'unset'};
`
 
export default ExpandedImage

For more information please see https://github.com/styled-components/styled-components

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.15219latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.15219
0.0.14145
0.0.130
0.0.121
0.0.110
0.0.101
0.0.90
0.0.80
0.0.70
0.0.60
0.0.51
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i styled-components-ts

Weekly Downloads

367

Version

0.0.15

License

WTFPL

Unpacked Size

5.67 kB

Total Files

6

Last publish

Collaborators

  • jacob-ebey