Skip to content

Commit d562278

Browse files
author
Hrithik-Gavankar
committed
refactor(NGUI-176): consolidate CSS to global.css and eliminate inline styles
1 parent 0f42ddb commit d562278

File tree

3 files changed

+107
-48
lines changed

3 files changed

+107
-48
lines changed

src/components/OneCardWrapper.tsx

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,51 +35,31 @@ const OneCardWrapper: React.FC<OneCardProps> = ({
3535
imageSize = "md",
3636
className,
3737
}) => {
38-
const getImageFlexBasis = () => {
39-
switch (imageSize) {
40-
case "sm":
41-
return "15%";
42-
case "lg":
43-
return "25%";
44-
default:
45-
return "20%";
46-
}
47-
};
4838

4939
return (
5040
<Card
5141
id={id}
52-
className={className}
53-
style={{
54-
maxWidth: "1440px",
55-
margin: "0 auto",
56-
width: "100%"
57-
}}
42+
className={`onecard-component-container ${className || ''}`}
5843
>
5944
<CardBody>
6045
<Flex spaceItems={{ default: "spaceItemsLg" }} alignItems={{ default: "alignItemsFlexStart" }}>
6146
{/* Left Column - Image */}
6247
{image && (
63-
<FlexItem shrink={{ default: "shrink" }} style={{ flexBasis: getImageFlexBasis() }}>
48+
<FlexItem className={`onecard-component-image-container size-${imageSize}`}>
6449
<img
6550
src={image}
6651
alt={title}
67-
style={{
68-
width: "100%",
69-
height: "auto",
70-
borderRadius: "var(--pf-global--BorderRadius--sm)",
71-
objectFit: "cover",
72-
}}
52+
className="onecard-component-img"
7353
/>
7454
</FlexItem>
7555
)}
7656

7757
{/* Right Column - Title + Fields */}
7858
<FlexItem grow={{ default: "grow" }}>
79-
<Title headingLevel="h4" size="lg" style={{ marginBottom: "16px" }}>
59+
<Title headingLevel="h4" size="lg" className="onecard-component-title">
8060
{title}
8161
</Title>
82-
<Divider component="div" style={{ marginTop: "16px", marginBottom: "16px" }} />
62+
<Divider component="div" className="onecard-component-divider" />
8363
<div>
8464
<DescriptionList isAutoFit>
8565
{fields?.map((field, idx) => (

src/components/VideoPlayerWrapper.tsx

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ import {
2727
controls = true,
2828
aspectRatio = '16:9',
2929
}) => {
30-
// Get aspect ratio styles
31-
const getAspectRatioStyle = () => {
30+
// Get aspect ratio class
31+
const getAspectRatioClass = () => {
3232
switch (aspectRatio) {
3333
case '16:9':
34-
return { paddingBottom: '56.25%' };
34+
return 'aspect-16-9';
3535
case '4:3':
36-
return { paddingBottom: '75%' };
36+
return 'aspect-4-3';
3737
case '1:1':
38-
return { paddingBottom: '100%' };
38+
return 'aspect-1-1';
3939
case 'auto':
4040
default:
41-
return {};
41+
return 'aspect-auto';
4242
}
4343
};
4444

@@ -76,25 +76,11 @@ import {
7676
if (isYouTubeUrl(video)) {
7777
// YouTube video embedding
7878
return (
79-
<div
80-
style={{
81-
position: 'relative',
82-
height: aspectRatio === 'auto' ? 'auto' : 0,
83-
overflow: 'hidden',
84-
...getAspectRatioStyle()
85-
}}
86-
>
79+
<div className={`video-player-container ${getAspectRatioClass()}`}>
8780
<iframe
8881
title={title}
8982
src={getYouTubeEmbedUrl(video)}
90-
style={{
91-
position: 'absolute',
92-
top: 0,
93-
left: 0,
94-
width: '100%',
95-
height: '100%',
96-
border: 0
97-
}}
83+
className="video-player-iframe"
9884
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
9985
referrerPolicy="strict-origin-when-cross-origin"
10086
allowFullScreen
@@ -109,6 +95,7 @@ import {
10995
controls={controls}
11096
autoPlay={autoPlay}
11197
title={title}
98+
className="video-player-video"
11299
>
113100
Your browser does not support the video tag.
114101
</video>
@@ -120,6 +107,7 @@ import {
120107
<img
121108
src={video_img}
122109
alt={title}
110+
className="video-player-poster"
123111
/>
124112
);
125113
}

src/global.css

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/* CSS Custom Properties for Dynamic Values */
2+
:root {
3+
--ngui-image-placeholder-height: 200px;
4+
--ngui-container-max-width: 1440px;
5+
--ngui-spacing-medium: 16px;
6+
--ngui-aspect-ratio-16-9: 56.25%;
7+
--ngui-aspect-ratio-4-3: 75%;
8+
--ngui-aspect-ratio-1-1: 100%;
9+
}
10+
111
/* Image Component Styles */
212
.image-component-img {
313
width: 100%;
@@ -8,11 +18,92 @@
818

919
.image-component-placeholder {
1020
width: 100%;
11-
height: 200px;
21+
height: var(--ngui-image-placeholder-height);
1222
background-color: var(--pf-global--Color--200);
1323
border-radius: var(--pf-global--BorderRadius--sm);
1424
display: flex;
1525
align-items: center;
1626
justify-content: center;
1727
color: var(--pf-global--Color--300);
1828
}
29+
30+
/* OneCard Component Styles */
31+
.onecard-component-img {
32+
width: 100%;
33+
height: auto;
34+
border-radius: var(--pf-global--BorderRadius--sm);
35+
object-fit: cover;
36+
}
37+
38+
.onecard-component-container {
39+
max-width: var(--ngui-container-max-width);
40+
margin: 0 auto;
41+
width: 100%;
42+
}
43+
44+
.onecard-component-image-container {
45+
flex-shrink: 0;
46+
}
47+
48+
.onecard-component-image-container.size-sm {
49+
flex-basis: 15%;
50+
}
51+
52+
.onecard-component-image-container.size-md {
53+
flex-basis: 20%;
54+
}
55+
56+
.onecard-component-image-container.size-lg {
57+
flex-basis: 25%;
58+
}
59+
60+
.onecard-component-title {
61+
margin-bottom: var(--ngui-spacing-medium);
62+
}
63+
64+
.onecard-component-divider {
65+
margin-top: var(--ngui-spacing-medium);
66+
margin-bottom: var(--ngui-spacing-medium);
67+
}
68+
69+
/* Video Player Component Styles */
70+
.video-player-container {
71+
position: relative;
72+
overflow: hidden;
73+
}
74+
75+
.video-player-container.aspect-16-9 {
76+
padding-bottom: var(--ngui-aspect-ratio-16-9);
77+
}
78+
79+
.video-player-container.aspect-4-3 {
80+
padding-bottom: var(--ngui-aspect-ratio-4-3);
81+
}
82+
83+
.video-player-container.aspect-1-1 {
84+
padding-bottom: var(--ngui-aspect-ratio-1-1);
85+
}
86+
87+
.video-player-container.aspect-auto {
88+
height: auto;
89+
}
90+
91+
.video-player-iframe {
92+
position: absolute;
93+
top: 0;
94+
left: 0;
95+
width: 100%;
96+
height: 100%;
97+
border: 0;
98+
}
99+
100+
.video-player-video,
101+
.video-player-poster {
102+
width: 100%;
103+
height: auto;
104+
}
105+
106+
.video-player-poster {
107+
border-radius: var(--pf-global--BorderRadius--sm);
108+
object-fit: cover;
109+
}

0 commit comments

Comments
 (0)