質問編集履歴

1

コード修正

2018/07/02 10:14

投稿

kt-sygo0921
kt-sygo0921

スコア11

test CHANGED
File without changes
test CHANGED
@@ -4,41 +4,91 @@
4
4
 
5
5
  ```Javascript
6
6
 
7
- const HeadingPresenter = ({
7
+ import React from "react";
8
8
 
9
- tag: Tag,
9
+ import ReactDOM from "react-dom";
10
10
 
11
- visualLevel,
12
11
 
13
- className,
14
12
 
15
- ...props
13
+ const HeadingPresenter = ({ tag: Tag, visualLevel, className, ...props }) => {
16
14
 
17
- }) => {
15
+ return (
18
16
 
19
- return <div>
17
+ <div>
20
18
 
21
- // Tagが動的に変更される(h1,h2等)想定です
19
+ <Tag className={"h"} {...props} />
22
20
 
23
- <Tag className={`h`} {...props} />
21
+ <style jsx>
24
22
 
25
- <style jsx>{`
23
+ {`
26
24
 
27
- .h {
25
+ .h {
28
26
 
29
- font-weight; 700;
27
+ font-weight: 700;
30
28
 
31
- line-height: 1.5;
29
+ line-height: 1.5;
32
30
 
31
+ color: red;
32
+
33
- }
33
+ }
34
34
 
35
35
  `}
36
36
 
37
- </style>
37
+ </style>
38
38
 
39
39
  </div>
40
40
 
41
+ );
42
+
41
43
  };
44
+
45
+
46
+
47
+ const HeadingContainer = ({ presenter, level = 2, visualLevel, ...props }) => {
48
+
49
+ level = Math.max(1, Math.min(6, level));
50
+
51
+ visualLevel = typeof visualLevel != "undefined" ? visualLevel : level;
52
+
53
+ const tag = `h${level}`;
54
+
55
+ // const tag = "h1";
56
+
57
+ return presenter({ tag, visualLevel, ...props });
58
+
59
+ };
60
+
61
+
62
+
63
+ const Heading = props => (
64
+
65
+ <HeadingContainer
66
+
67
+ presenter={presenterProps => <HeadingPresenter {...presenterProps} />}
68
+
69
+ {...props}
70
+
71
+ />
72
+
73
+ );
74
+
75
+
76
+
77
+ const rootElement = document.getElementById("root");
78
+
79
+ ReactDOM.render(
80
+
81
+ <Heading tag="h1" className="sample">
82
+
83
+ ほげほげ
84
+
85
+ </Heading>,
86
+
87
+ rootElement
88
+
89
+ );
90
+
91
+
42
92
 
43
93
  ```
44
94