mirror of
https://github.com/jaronpate/unicord.git
synced 2026-10-18 21:47:40 +00:00
refactor: Update Section and PackageManager components for improved type safety and consistency
This commit includes the following changes: - Refactored PackageManager to use a more type-safe approach - Updated Section component to use semantic `<section>` tag - Adjusted background prop types and default values - Simplified type definitions - Improved code readability and maintainability
This commit is contained in:
@@ -3,40 +3,46 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import styles from './PackageManager.module.css';
|
import styles from './PackageManager.module.css';
|
||||||
|
|
||||||
const PACKAGE_MANAGERS = {
|
const PACKAGE_MANAGERS = ['npm', 'yarn', 'pnpm', 'bun'] as const;
|
||||||
npm: 'npm install unicord',
|
type PackageManager = typeof PACKAGE_MANAGERS[number];
|
||||||
yarn: 'yarn add unicord',
|
|
||||||
pnpm: 'pnpm add unicord',
|
|
||||||
bun: 'bun add unicord'
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export function PackageManager() {
|
export function PackageManager() {
|
||||||
const [activeTab, setActiveTab] = useState<keyof typeof PACKAGE_MANAGERS>('npm');
|
const [activeTab, setActiveTab] = useState<PackageManager>('npm');
|
||||||
|
|
||||||
return (
|
const getInstallCommand = (pm: PackageManager) => {
|
||||||
<div className={styles.container}>
|
const commands = {
|
||||||
<div className={styles.tabs}>
|
npm: 'npm install unicord',
|
||||||
{Object.keys(PACKAGE_MANAGERS).map(pm => (
|
yarn: 'yarn add unicord',
|
||||||
<button
|
pnpm: 'pnpm add unicord',
|
||||||
key={pm}
|
bun: 'bun add unicord'
|
||||||
className={`${styles.tab} ${activeTab === pm ? styles.active : ''}`}
|
};
|
||||||
onClick={() => setActiveTab(pm as keyof typeof PACKAGE_MANAGERS)}
|
return commands[pm];
|
||||||
>
|
};
|
||||||
{pm}
|
|
||||||
</button>
|
return (
|
||||||
))}
|
<div className={styles.container}>
|
||||||
</div>
|
<div className={styles.tabs}>
|
||||||
<div className={styles.commandWrapper}>
|
{PACKAGE_MANAGERS.map(pm => (
|
||||||
<code className={styles.command}>
|
<button
|
||||||
{PACKAGE_MANAGERS[activeTab]}
|
key={pm}
|
||||||
</code>
|
className={`${styles.tab} ${activeTab === pm ? styles.active : ''}`}
|
||||||
<button
|
onClick={() => setActiveTab(pm)}
|
||||||
className={styles.copyButton}
|
>
|
||||||
onClick={() => navigator.clipboard.writeText(PACKAGE_MANAGERS[activeTab])}
|
{pm}
|
||||||
>
|
</button>
|
||||||
Copy
|
))}
|
||||||
</button>
|
</div>
|
||||||
</div>
|
<div className={styles.commandWrapper}>
|
||||||
</div>
|
<code className={styles.command}>
|
||||||
);
|
{getInstallCommand(activeTab)}
|
||||||
|
</code>
|
||||||
|
<button
|
||||||
|
className={styles.copyButton}
|
||||||
|
onClick={() => navigator.clipboard.writeText(getInstallCommand(activeTab))}
|
||||||
|
>
|
||||||
|
Copy
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
.section {
|
.section {
|
||||||
padding: var(--section-padding-desktop);
|
padding: 6rem 12em;
|
||||||
min-height: 50vh;
|
min-height: 50vh;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
position: relative;
|
position: relative;
|
||||||
border-top: 1px solid var(--gray-alpha-200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark {
|
.dark {
|
||||||
background: var(--gray-alpha-100);
|
background: var(--gray-alpha-100);
|
||||||
|
border-top: 1px solid var(--gray-alpha-200);
|
||||||
|
}
|
||||||
|
|
||||||
|
.light {
|
||||||
|
border-top: 1px solid var(--gray-alpha-200);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 1200px) {
|
@media (max-width: 1200px) {
|
||||||
.section {
|
.section {
|
||||||
padding: var(--section-padding-mobile);
|
padding: 4rem 2rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ import styles from './Section.module.css';
|
|||||||
|
|
||||||
type SectionProps = {
|
type SectionProps = {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
background?: 'default' | 'dark';
|
background?: 'light' | 'dark';
|
||||||
className?: string;
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function Section({ children, background = 'default', className = '' }: SectionProps) {
|
export function Section({ children, background = 'light', className = '' }: SectionProps) {
|
||||||
return (
|
return (
|
||||||
<div className={`${styles.section} ${styles[background]} ${className}`}>
|
<section className={`${styles.section} ${styles[background]} ${className}`}>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user