-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/forwardRef
- Loading branch information
Showing
23 changed files
with
87 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,33 @@ | ||
import * as React from 'react'; | ||
import { styled } from './utils'; | ||
|
||
import { borderRadius, height, opacity, styled, width } from './utils'; | ||
import { Box, IBoxProps } from './Box'; | ||
|
||
import { BorderRadius } from './types'; | ||
|
||
export interface IImageProps { | ||
src: string; | ||
label?: string; | ||
radius?: BorderRadius; | ||
export interface IImageProps extends IBoxProps { | ||
src: HTMLImageElement['src']; | ||
alt?: HTMLImageElement['alt']; | ||
title?: HTMLImageElement['title']; | ||
hidden?: boolean; | ||
opacity?: number; | ||
responsive?: boolean; | ||
height?: string; | ||
width?: string; | ||
} | ||
|
||
interface IPlainImageProps extends IImageProps { | ||
className: string; | ||
height?: HTMLImageElement['height']; | ||
width?: HTMLImageElement['width']; | ||
} | ||
|
||
const PlainImage = (props: IPlainImageProps) => <img className={props.className} src={props.src} title={props.label} />; | ||
|
||
export const Image = styled<IImageProps, 'img'>(PlainImage as any)( | ||
{ | ||
// @ts-ignore | ||
display: 'inline', | ||
}, | ||
|
||
borderRadius, | ||
opacity, | ||
width, | ||
height, | ||
|
||
({ hidden }: IImageProps) => | ||
hidden && { | ||
display: 'none', | ||
}, | ||
export const Image = styled<IImageProps, 'img'>(Box).attrs({ | ||
as: 'img', | ||
})( | ||
// @ts-ignore | ||
({ hidden }: IImageProps) => hidden && { display: 'none' }, | ||
|
||
({ responsive }: IImageProps) => | ||
responsive && { | ||
width: 'auto', | ||
height: 'auto', | ||
maxWidth: '100%', | ||
maxHeight: '100%', | ||
} | ||
); | ||
|
||
Image.defaultProps = { | ||
circular: false, | ||
label: '', | ||
height: 'auto', | ||
hidden: false, | ||
opacity: 1, | ||
responsive: true, | ||
rounded: false, | ||
width: 'auto', | ||
responsive: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { mount } from 'enzyme'; | ||
import 'jest-enzyme'; | ||
import * as React from 'react'; | ||
import { IImageProps, Image } from '../Image'; | ||
|
||
describe('Image', () => { | ||
let props: IImageProps; | ||
|
||
beforeEach(() => { | ||
props = { | ||
title: 'Stoplight.io', | ||
src: 'www.stoplight.io', | ||
}; | ||
}); | ||
|
||
it('attaches title', () => { | ||
const wrapper = mount(<Image {...props} />); | ||
expect(wrapper).toHaveProp('title', props.title); | ||
wrapper.unmount(); | ||
}); | ||
|
||
it('attaches src', () => { | ||
const wrapper = mount(<Image {...props} />); | ||
expect(wrapper).toHaveProp('src', props.src); | ||
wrapper.unmount(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters