mirror of
https://github.com/rjNemo/react_template
synced 2026-06-06 07:26: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 { About } from './components/About';
|
||||
import { Home } from './containers/Home';
|
||||
import { Home } from './containers/home';
|
||||
|
||||
const Router: FC = () => (
|
||||
<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 Todo from '../core/models/todo';
|
||||
import Todo from '../../core/models/todo';
|
||||
|
||||
interface Props {
|
||||
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 * as serviceWorker from './serviceWorker';
|
||||
import { ThemeProvider } from 'styled-components';
|
||||
import { myTheme } from './core/theme';
|
||||
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
<BrowserRouter>
|
||||
<App />
|
||||
</BrowserRouter>
|
||||
<ThemeProvider theme={myTheme}>
|
||||
<BrowserRouter>
|
||||
<App />
|
||||
</BrowserRouter>
|
||||
</ThemeProvider>
|
||||
</React.StrictMode>,
|
||||
document.getElementById('root')
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue