Skip to content

Commit

Permalink
Use css modules
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbaumgertner committed Jan 12, 2025
1 parent 62a182c commit c29b615
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 37 deletions.
32 changes: 32 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@ const config: StorybookConfig = {
name: "@storybook/nextjs",
options: {},
},
webpackFinal: (config: any = { module: { rules: [] } }) => {
if (!config.module?.rules) {
config.module = { rules: [] };
}

const cssRule = config.module.rules.find((rule: any) =>
rule?.test?.toString().includes("css")
);

if (cssRule) {
cssRule.test = /\.css$/;
cssRule.exclude = /\.module\.css$/;
}

// Add specific rule for CSS Modules
config.module.rules.push({
test: /\.module\.css$/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
modules: {
localIdentName: "[name]__[local]___[hash:base64:5]",
},
},
},
],
});

return config;
},
};

export default config;
14 changes: 0 additions & 14 deletions components/TimeSpanBar/TimeSpanBar.css

This file was deleted.

57 changes: 57 additions & 0 deletions components/TimeSpanBar/TimeSpanBar.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.component {
border: 1px solid #fae6c6;
padding: 12px 16px;
border-radius: 4px;
display: flex;
flex-direction: column;
gap: 8px;
}

.header {
font-size: 16px;
font-weight: 600;
}

.content {
display: flex;
flex-direction: row;
gap: 8px;
}

.start {
display: flex;
flex-direction: column;
gap: 4px;
}

.end {
display: flex;
flex-direction: column;
gap: 4px;
}

.image {
width: 64px;
height: 64px;
}

.label {
font-size: 14px;
font-weight: 400;
}

.date {
font-size: 14px;
font-weight: 400;
}

.events {
display: flex;
flex-direction: column;
gap: 4px;
}

.event {
font-size: 14px;
font-weight: 400;
}
35 changes: 13 additions & 22 deletions components/TimeSpanBar/TimeSpanBar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";

import "./TimeSpanBar.css";
import classes from "./TimeSpanBar.module.css";

type TimeSpanBarProps = {
startDate: Date;
Expand All @@ -21,32 +21,23 @@ const TimeSpanBar = ({
image,
}: TimeSpanBarProps) => {
return (
<div className="time-span-bar">
<div className="time-span-bar__header">{header}</div>
<div className="time-span-bar__content">
<div className="time-span-bar__start-date">
<div className="time-span-bar__label">Дата рождения</div>
<div className="time-span-bar__date">
{startDate.toLocaleDateString()}
</div>
<div className={classes.component}>
<div className={classes.header}>{header}</div>
<div className={classes.content}>
<div className={classes.start}>
<div className={classes.label}>Дата рождения</div>
<div className={classes.date}>{startDate.toLocaleDateString()}</div>
</div>
<img
width={64}
src={image}
alt={header}
className="time-span-bar__image"
/>
<div className="time-span-bar__events">
<img width={64} src={image} alt={header} className={classes.image} />
<div className={classes.events}>
{events.map((event) => (
<div className="time-span-bar__event">{event.name}</div>
<div className={classes.event}>{event.name}</div>
))}
</div>
{endDate && (
<div className="time-span-bar__end-date">
<div className="time-span-bar__label">Дата смерти</div>
<div className="time-span-bar__date">
{endDate.toLocaleDateString()}
</div>
<div className={classes.end}>
<div className={classes.label}>Дата смерти</div>
<div className={classes.date}>{endDate.toLocaleDateString()}</div>
</div>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"jsx": "preserve",
"incremental": true
},
"include": ["**/*.ts", "**/*.tsx"],
"include": ["**/*.ts", "**/*.tsx", "types/**/*.d.ts"],
"exclude": ["node_modules"]
}
4 changes: 4 additions & 0 deletions types/css.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.module.css" {
const classes: { [key: string]: string };
export default classes;
}

0 comments on commit c29b615

Please sign in to comment.