forked from sombochea/verdaccio-ui
feat: Added Theme and migrate to emotion@10.x 🚀 (#286)
* chore: updated emotion dependency * feat: introduced theme * refactor: updated emotion styles * fix: fixed emotion error * fix: fixed tests * chore: add missing types Co-Authored-By: Thomas Klein <tmkn@users.noreply.github.com>
This commit is contained in:
committed by
Juan Picado @jotadeveloper
parent
a0dcf87368
commit
111f0c50e5
@@ -1,5 +1,6 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
|
||||
import { render } from '../../utils/test-react-testing-library';
|
||||
|
||||
import Icon from './Icon';
|
||||
|
||||
@@ -8,7 +9,7 @@ describe('<Icon /> component', () => {
|
||||
name: 'austria',
|
||||
};
|
||||
test('should render the component in default state', () => {
|
||||
const wrapper = shallow(<Icon name={props.name} />);
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
const { container } = render(<Icon name={props.name} />);
|
||||
expect(container.firstChild).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -63,10 +63,11 @@ export interface Props {
|
||||
modifiers?: null | undefined;
|
||||
}
|
||||
|
||||
/* eslint-disable verdaccio/jsx-spread */
|
||||
const Icon: React.FC<Props> = ({ className, name, size = 'sm', img = false, pointer = false, ...props }) => {
|
||||
const title = capitalize(name.toString());
|
||||
return img ? (
|
||||
<ImgWrapper className={className} name={name} pointer={pointer} size={size} title={title} {...props}>
|
||||
<ImgWrapper className={className} pointer={pointer} size={size} title={title} {...props}>
|
||||
<Img alt={title} src={Icons[name]} />
|
||||
</ImgWrapper>
|
||||
) : (
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`<Icon /> component should render the component in default state 1`] = `"<svg class=\\"css-j2zgvv ek145dl0\\"><title>Austria</title><use xlink:href=\\"[object Object]#austria\\"></use></svg>"`;
|
||||
exports[`<Icon /> component should render the component in default state 1`] = `
|
||||
.emotion-0 {
|
||||
box-sizing: initial;
|
||||
display: inline-block;
|
||||
cursor: default;
|
||||
width: 14px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
<svg
|
||||
class="emotion-0 emotion-1"
|
||||
>
|
||||
<title>
|
||||
Austria
|
||||
</title>
|
||||
<use
|
||||
xlink:href="[object Object]#austria"
|
||||
/>
|
||||
</svg>
|
||||
`;
|
||||
|
||||
@@ -1,54 +1,42 @@
|
||||
import styled, { css } from 'react-emotion';
|
||||
import styled from '@emotion/styled';
|
||||
import { Breakpoint } from '@material-ui/core/styles/createBreakpoints';
|
||||
import { StyledOtherComponent } from 'create-emotion-styled';
|
||||
import { DetailedHTMLProps, HTMLAttributes } from 'react';
|
||||
|
||||
const getSize = (size: Breakpoint): string => {
|
||||
const getSize = (size: Breakpoint): { width: number; height: number } => {
|
||||
switch (size) {
|
||||
case 'md':
|
||||
return `
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
`;
|
||||
return {
|
||||
width: 18,
|
||||
height: 18,
|
||||
};
|
||||
default:
|
||||
return `
|
||||
width: 14px;
|
||||
height: 16px;
|
||||
`;
|
||||
return {
|
||||
width: 14,
|
||||
height: 16,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const commonStyle = ({ size = 'sm' as Breakpoint, pointer, modifiers = null }): string => css`
|
||||
&& {
|
||||
display: inline-block;
|
||||
cursor: ${pointer ? 'pointer' : 'Developers'};
|
||||
${getSize(size)};
|
||||
${modifiers && modifiers};
|
||||
}
|
||||
`;
|
||||
interface CommonStyleProps {
|
||||
size: Breakpoint;
|
||||
pointer?: boolean;
|
||||
}
|
||||
const commonStyle = ({ size = 'sm', pointer }: CommonStyleProps): object => ({
|
||||
display: 'inline-block',
|
||||
cursor: pointer ? 'pointer' : 'default',
|
||||
...getSize(size),
|
||||
});
|
||||
|
||||
export const Svg = styled('svg')`
|
||||
${commonStyle};
|
||||
box-sizing: initial;
|
||||
`;
|
||||
export const Svg = styled('svg')<CommonStyleProps>(props => ({
|
||||
boxSizing: 'initial',
|
||||
...commonStyle(props),
|
||||
}));
|
||||
|
||||
export const ImgWrapper: StyledOtherComponent<
|
||||
{
|
||||
size?: Breakpoint;
|
||||
pointer: boolean;
|
||||
modifiers?: null | undefined;
|
||||
name?: string | unknown;
|
||||
},
|
||||
DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>,
|
||||
{}
|
||||
> = styled('span')`
|
||||
${commonStyle};
|
||||
box-sizing: initial;
|
||||
`;
|
||||
export const ImgWrapper = styled('span')<CommonStyleProps>(props => ({
|
||||
boxSizing: 'initial',
|
||||
...commonStyle(props),
|
||||
}));
|
||||
|
||||
export const Img = styled('img')({
|
||||
'&&': {
|
||||
width: '100%',
|
||||
height: 'auto',
|
||||
},
|
||||
width: '100%',
|
||||
height: 'auto',
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user