mirror of
https://github.com/rjNemo/react_template
synced 2026-06-10 14:16:40 +00:00
set types for styled component
This commit is contained in:
parent
a3353418dc
commit
55698db937
9 changed files with 83 additions and 14 deletions
|
|
@ -2,7 +2,7 @@ import React, { FC } from 'react';
|
||||||
import { Route, Switch } from 'react-router-dom';
|
import { Route, Switch } from 'react-router-dom';
|
||||||
|
|
||||||
import { About } from './components/About';
|
import { About } from './components/About';
|
||||||
import { Home } from './containers/Home';
|
import { Home } from './containers/home';
|
||||||
|
|
||||||
const Router: FC = () => (
|
const Router: FC = () => (
|
||||||
<Switch>
|
<Switch>
|
||||||
|
|
|
||||||
21
src/components/button.tsx
Normal file
21
src/components/button.tsx
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
import styled, { css } from 'styled-components';
|
||||||
|
|
||||||
|
interface ButtonProps {
|
||||||
|
readonly primary: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Button = styled.button<ButtonProps>`
|
||||||
|
background: transparent;
|
||||||
|
border-radius: 3px;
|
||||||
|
border: 2px solid ${(props) => props.theme.colors.primary};
|
||||||
|
color: ${(props) => props.theme.colors.primary};
|
||||||
|
margin: 0 1em;
|
||||||
|
padding: 0 0.25em 1em;
|
||||||
|
|
||||||
|
${(props) =>
|
||||||
|
props.primary &&
|
||||||
|
css`
|
||||||
|
background: ${(props) => props.theme.colors.primary};
|
||||||
|
color: white;
|
||||||
|
`}
|
||||||
|
`;
|
||||||
5
src/components/container.tsx
Normal file
5
src/components/container.tsx
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
export const Container = styled.div`
|
||||||
|
text-align: center;
|
||||||
|
`;
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
import React, { FC } from 'react';
|
|
||||||
|
|
||||||
import { listTodos } from '../core/services/todo';
|
|
||||||
import { TodoList } from '../components/TodoList';
|
|
||||||
|
|
||||||
export const Home: FC = () => {
|
|
||||||
const todos = listTodos();
|
|
||||||
return <TodoList todos={todos} />;
|
|
||||||
};
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
import Todo from '../core/models/todo';
|
import Todo from '../../core/models/todo';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
todos: Todo[];
|
todos: Todo[];
|
||||||
28
src/containers/home/index.tsx
Normal file
28
src/containers/home/index.tsx
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import React, { FC } from 'react';
|
||||||
|
|
||||||
|
import { TodoList } from './TodoList';
|
||||||
|
import { Button } from '../../components/button';
|
||||||
|
|
||||||
|
import Todo from '../../core/models/todo';
|
||||||
|
import { listTodos } from '../../core/services/todo';
|
||||||
|
import { Container } from '../../components/container';
|
||||||
|
|
||||||
|
export const Home: FC = () => {
|
||||||
|
const todos: Todo[] = listTodos();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Your tasks</h1>
|
||||||
|
<p>Hi there!</p>
|
||||||
|
<TodoList todos={todos} />
|
||||||
|
<Container>
|
||||||
|
<Button primary onClick={() => console.log('Clicked Normal Button')}>
|
||||||
|
Normal Button
|
||||||
|
</Button>
|
||||||
|
<Button primary onClick={() => console.log('Clicked Primary Button')}>
|
||||||
|
Primary Button
|
||||||
|
</Button>
|
||||||
|
</Container>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
9
src/core/theme/index.ts
Normal file
9
src/core/theme/index.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { DefaultTheme } from 'styled-components';
|
||||||
|
|
||||||
|
export const myTheme: DefaultTheme = {
|
||||||
|
borderRadius: '5px',
|
||||||
|
colors: {
|
||||||
|
primary: 'palevioletred',
|
||||||
|
secondary: 'magenta'
|
||||||
|
}
|
||||||
|
};
|
||||||
11
src/core/theme/styled.d.ts
vendored
Normal file
11
src/core/theme/styled.d.ts
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
import 'styled-components';
|
||||||
|
|
||||||
|
declare module 'styled-components' {
|
||||||
|
export interface DefaultTheme {
|
||||||
|
borderRadius: string;
|
||||||
|
colors: {
|
||||||
|
primary: string;
|
||||||
|
secondary: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,12 +4,16 @@ import { BrowserRouter } from 'react-router-dom';
|
||||||
|
|
||||||
import App from './App';
|
import App from './App';
|
||||||
import * as serviceWorker from './serviceWorker';
|
import * as serviceWorker from './serviceWorker';
|
||||||
|
import { ThemeProvider } from 'styled-components';
|
||||||
|
import { myTheme } from './core/theme';
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<BrowserRouter>
|
<ThemeProvider theme={myTheme}>
|
||||||
<App />
|
<BrowserRouter>
|
||||||
</BrowserRouter>
|
<App />
|
||||||
|
</BrowserRouter>
|
||||||
|
</ThemeProvider>
|
||||||
</React.StrictMode>,
|
</React.StrictMode>,
|
||||||
document.getElementById('root')
|
document.getElementById('root')
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue