File tree Expand file tree Collapse file tree 3 files changed +59
-80
lines changed Expand file tree Collapse file tree 3 files changed +59
-80
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,16 @@ export const Default = () => {
20
20
< Score score = { 9 } />
21
21
< Score score = { 10 } />
22
22
< Score score = { 11 } />
23
- < p > ^ We only go up to 10 at the moment 🤷♀</ p >
23
+ < Score score = { 12 } />
24
+ < Score score = { 13 } />
25
+ < Score score = { 14 } />
26
+ < Score score = { 15 } />
27
+ < Score score = { 16 } />
28
+ < Score score = { 17 } />
29
+ < Score score = { 18 } />
30
+ < Score score = { 31 } />
31
+ < Score score = { 0.5 } />
32
+ < Score score = { NaN } />
24
33
</ >
25
34
) ;
26
35
} ;
Original file line number Diff line number Diff line change 1
1
import { css } from '@emotion/react' ;
2
- import { text } from '@guardian/source/foundations ' ;
2
+ import { palette } from '../palette ' ;
3
3
import { Eight } from './numbers/Eight' ;
4
4
import { Five } from './numbers/Five' ;
5
5
import { Four } from './numbers/Four' ;
@@ -12,103 +12,69 @@ import { Three } from './numbers/Three';
12
12
import { Two } from './numbers/Two' ;
13
13
import { Zero } from './numbers/Zero' ;
14
14
15
+ const ScoreStyles = ( { children } : { children : React . ReactNode } ) => (
16
+ < div
17
+ css = { css `
18
+ position : relative;
19
+ width : 3.75rem ;
20
+ height : 3.75rem ;
21
+ border-radius : 1.875rem ;
22
+ border : 0.0625rem solid ${ palette ( '--football-score-border' ) } ;
23
+ display : flex;
24
+ align-items : center;
25
+ justify-content : center;
26
+ ` }
27
+ >
28
+ { children }
29
+ </ div >
30
+ ) ;
31
+
15
32
type Props = {
16
33
score : number ;
17
34
} ;
18
35
19
- export const Score = ( { score } : Props ) => {
20
- const ScoreStyles = ( { children } : { children : React . ReactNode } ) => (
21
- < div
22
- css = { css `
23
- position : relative;
24
- width : 3.75rem ;
25
- height : 3.75rem ;
26
- border-radius : 1.875rem ;
27
- border : 0.0625rem solid ${ text . primary } ;
28
-
29
- svg {
30
- position : absolute;
31
- top : 0 ;
32
- left : 0 ;
33
- right : 0 ;
34
- bottom : 0 ;
35
- margin : auto;
36
- }
37
- ` }
38
- >
39
- { children }
40
- </ div >
41
- ) ;
42
-
43
- if ( Number . isNaN ( score ) ) return < ScoreStyles > </ ScoreStyles > ;
36
+ const ScoreNumber = ( { score } : Props ) => {
37
+ if ( ! Number . isInteger ( score ) || score < 0 ) {
38
+ return null ;
39
+ }
44
40
45
41
switch ( score ) {
46
42
case 0 :
47
- return (
48
- < ScoreStyles >
49
- < Zero />
50
- </ ScoreStyles >
51
- ) ;
43
+ return < Zero /> ;
52
44
case 1 :
53
- return (
54
- < ScoreStyles >
55
- < One />
56
- </ ScoreStyles >
57
- ) ;
45
+ return < One /> ;
58
46
case 2 :
59
- return (
60
- < ScoreStyles >
61
- < Two />
62
- </ ScoreStyles >
63
- ) ;
47
+ return < Two /> ;
64
48
case 3 :
65
- return (
66
- < ScoreStyles >
67
- < Three />
68
- </ ScoreStyles >
69
- ) ;
49
+ return < Three /> ;
70
50
case 4 :
71
- return (
72
- < ScoreStyles >
73
- < Four />
74
- </ ScoreStyles >
75
- ) ;
51
+ return < Four /> ;
76
52
case 5 :
77
- return (
78
- < ScoreStyles >
79
- < Five />
80
- </ ScoreStyles >
81
- ) ;
53
+ return < Five /> ;
82
54
case 6 :
83
- return (
84
- < ScoreStyles >
85
- < Six />
86
- </ ScoreStyles >
87
- ) ;
55
+ return < Six /> ;
88
56
case 7 :
89
- return (
90
- < ScoreStyles >
91
- < Seven />
92
- </ ScoreStyles >
93
- ) ;
57
+ return < Seven /> ;
94
58
case 8 :
95
- return (
96
- < ScoreStyles >
97
- < Eight />
98
- </ ScoreStyles >
99
- ) ;
59
+ return < Eight /> ;
100
60
case 9 :
101
- return (
102
- < ScoreStyles >
103
- < Nine />
104
- </ ScoreStyles >
105
- ) ;
61
+ return < Nine /> ;
106
62
case 10 :
63
+ return < Ten /> ;
107
64
default :
108
65
return (
109
- < ScoreStyles >
110
- < Ten />
111
- </ ScoreStyles >
66
+ < >
67
+ < ScoreNumber score = { Math . trunc ( score / 10 ) } />
68
+ < ScoreNumber score = { score % 10 } />
69
+ </ >
112
70
) ;
113
71
}
114
72
} ;
73
+
74
+ export const Score = ( { score } : Props ) => {
75
+ return (
76
+ < ScoreStyles >
77
+ < ScoreNumber score = { score } />
78
+ </ ScoreStyles >
79
+ ) ;
80
+ } ;
Original file line number Diff line number Diff line change @@ -6595,6 +6595,10 @@ const paletteColours = {
6595
6595
light : ( ) => sourcePalette . sport [ 500 ] ,
6596
6596
dark : ( ) => sourcePalette . sport [ 500 ] ,
6597
6597
} ,
6598
+ '--football-score-border' : {
6599
+ light : ( ) => sourcePalette . neutral [ 7 ] ,
6600
+ dark : ( ) => sourcePalette . neutral [ 7 ] ,
6601
+ } ,
6598
6602
'--football-sub-text' : {
6599
6603
light : ( ) => sourcePalette . neutral [ 46 ] ,
6600
6604
dark : ( ) => sourcePalette . neutral [ 73 ] ,
You can’t perform that action at this time.
0 commit comments