Passed
Push — main ( cafa69...3c9e73 )
by Andrii
02:00
created

App.tsx ➔ Link   A

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 9
c 0
b 0
f 0
rs 10
cc 1
1
import React, { PropsWithChildren } from 'react';
2
import logo from './logo.svg';
3
import type { ClassNames, ClassNamesProperty, ClassHash} from "react-classnaming"
4
import { 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, ClassNamesProperty<{"App-logo": ClassHash}>>) => {
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 AppClassNames = ClassNamesProperty<{
17
  App: ClassHash
18
  App_header: ClassHash
19
}>
20
type AppProps = AppClassNames & ClassNames<typeof Logo, LinkProps, typeof Body>
21
function AppComponent({classnames, classnames: {App}}: AppProps) {
22
  const classNaming = classNamingCtx({classnames})
23
  return (
24
    <div {...classNamingCtx({App})}>
25
      <Header {...classNaming({App_header: true})}>
26
        <Logo {...classNaming()} {...{classnames}}/>
27
        <Body/>
28
        <Link {...{...classNaming(), classnames}}/>
29
      </Header>
30
    </div>
31
  );
32
}
33
34
export default AppComponent;
35
36
type LinkProps = ClassNamesProperty<{"App-link": ClassHash}>
37
function Link({classnames: {"App-link": appLink}}: LinkProps) {
38
  return <a
39
    {...classNamingCtx<LinkProps["classnames"]>({"App-link": appLink})}
40
    href="https://reactjs.org"
41
    target="_blank"
42
    rel="noopener noreferrer"
43
  >
44
    Learn React
45
  </a>    
46
}
47