1
|
|
|
import React, { PropsWithChildren } from 'react'; |
2
|
|
|
import logo from './logo.svg'; |
3
|
|
|
import type { ClassNames} from "react-classnaming" |
4
|
|
|
import { classNamingBasic, classNamingCtx } from "react-classnaming" |
5
|
|
|
|
6
|
|
|
const Header = ({className, children}: PropsWithChildren<ClassNames<true>>) => |
7
|
|
|
<header {...{className}}>{children}</header>; |
8
|
|
|
|
9
|
|
|
const Logo = (props: ClassNames<true, "App-logo">) => { |
10
|
|
|
const classNaming = classNamingCtx(props) |
11
|
|
|
return <img src={logo} {...classNaming({"App-logo": true})} alt="logo" /> |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
const Body = () => <p>Edit <code>src/App.tsx</code> and save to reload.</p> |
15
|
|
|
|
16
|
|
|
type AppProps = ClassNames<"App"|"App_header", typeof Logo, LinkProps, typeof Body> |
17
|
|
|
function AppComponent({classnames, classnames: {App}}: AppProps) { |
18
|
|
|
const classNaming = classNamingCtx({classnames}, {withClassNames: true}) |
19
|
|
|
return ( |
20
|
|
|
<div {...classNamingBasic({App})}> |
21
|
|
|
<Header {...classNaming({App_header: true})}> |
22
|
|
|
<Logo {...classNaming()}/> |
23
|
|
|
<Body/> |
24
|
|
|
<Link {...classNaming()}/> |
25
|
|
|
</Header> |
26
|
|
|
</div> |
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
export default AppComponent; |
31
|
|
|
|
32
|
|
|
type LinkProps = ClassNames<"App-link"> |
33
|
|
|
function Link({classnames: {"App-link": appLink}}: LinkProps) { |
34
|
|
|
return <a |
35
|
|
|
{...classNamingBasic<LinkProps>({"App-link": appLink})} |
36
|
|
|
href="https://reactjs.org" |
37
|
|
|
target="_blank" |
38
|
|
|
rel="noopener noreferrer" |
39
|
|
|
> |
40
|
|
|
Learn React |
41
|
|
|
</a> |
42
|
|
|
} |
43
|
|
|
|