Skip to content

Commit a061202

Browse files
authored
Adapting layout and headlines components to ShadCN + issues resolved (#1771)
* adapting the layout for shadcn and adjusting creating a test file * adding hover effects for the blog cards * adapts the headlines to shadcn * adjusting coloring and tets for headlines component * format adjustments * format adjustments
1 parent cad3078 commit a061202

File tree

5 files changed

+579
-143
lines changed

5 files changed

+579
-143
lines changed

components/Headlines.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
/* eslint-disable linebreak-style */
12
import React, { useState, useEffect } from 'react';
2-
import classnames from 'classnames';
3+
import { cn } from '~/lib/utils';
34
import slugifyMarkdownHeadline from '~/lib/slugifyMarkdownHeadline';
45
import { useRouter } from 'next/router';
56
import { HOST } from '~/lib/config';
@@ -64,9 +65,9 @@ const Headline = ({
6465
const attributes = {
6566
...propAttributes,
6667
id: propAttributes?.slug || slug,
67-
className: classnames(
68+
className: cn(
6869
'group cursor-pointer hover:underline',
69-
{ 'text-startBlue dark:text-endBlue': isActive },
70+
isActive && 'text-startBlue',
7071
propAttributes?.className,
7172
),
7273
onClick: handleHeadingClick,
@@ -77,9 +78,7 @@ const Headline = ({
7778
<Tag attributes={attributes}>
7879
{childredWithoutFragment}
7980
{isActive && (
80-
<span className={'text-startBlue dark:text-endBlue inline-block ml-2'}>
81-
82-
</span>
81+
<span className={'text-startBlue inline-block ml-2'}></span>
8382
)}
8483
</Tag>
8584
);
@@ -97,9 +96,9 @@ type TagProps = { children: React.ReactNode; attributes: Record<string, any> };
9796
const Headline1Tag = ({ children, attributes }: TagProps) => (
9897
<h1
9998
{...attributes}
100-
className={classnames(
101-
attributes?.className,
99+
className={cn(
102100
'text-h1mobile md:text-h1 dark:text-slate-200 font-bold pt-10 mb-6',
101+
attributes?.className,
103102
)}
104103
>
105104
{children}
@@ -108,9 +107,9 @@ const Headline1Tag = ({ children, attributes }: TagProps) => (
108107
const Headline2Tag = ({ children, attributes }: TagProps) => (
109108
<h2
110109
{...attributes}
111-
className={classnames(
112-
attributes?.className,
110+
className={cn(
113111
'text-h2mobile md:text-h2 dark:text-slate-200 font-semibold mt-10 mb-4',
112+
attributes?.className,
114113
)}
115114
>
116115
{children}
@@ -119,9 +118,9 @@ const Headline2Tag = ({ children, attributes }: TagProps) => (
119118
const Headline3Tag = ({ children, attributes }: TagProps) => (
120119
<h3
121120
{...attributes}
122-
className={classnames(
123-
attributes?.className,
121+
className={cn(
124122
'text-h3mobile dark:text-slate-200 md:text-h3 font-semibold mt-6 mb-3',
123+
attributes?.className,
125124
)}
126125
>
127126
{children}
@@ -130,9 +129,9 @@ const Headline3Tag = ({ children, attributes }: TagProps) => (
130129
const Headline4Tag = ({ children, attributes }: TagProps) => (
131130
<h4
132131
{...attributes}
133-
className={classnames(
134-
attributes?.className,
132+
className={cn(
135133
'text-h4mobile dark:text-slate-200 md:text-h4 font-semibold mt-4 mb-2',
134+
attributes?.className,
136135
)}
137136
>
138137
{children}

components/Layout.tsx

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable linebreak-style */
2+
/* istanbul ignore file */
13
import React, { useContext, useEffect, useState, useRef } from 'react';
24
import Head from 'next/head';
35
import Link from 'next/link';
@@ -10,7 +12,8 @@ import { useTheme } from 'next-themes';
1012
import DarkModeToggle from './DarkModeToggle';
1113
import ScrollButton from './ScrollButton';
1214
import Image from 'next/image';
13-
/* istanbul ignore file */
15+
import { Button } from '@/components/ui/button';
16+
1417
type Props = {
1518
children: React.ReactNode;
1619
mainClassName?: string;
@@ -262,28 +265,32 @@ const MainNavigation = () => {
262265
)}
263266
</div>
264267
<div className='flex items-center justify-end mr-8'>
265-
<a
268+
<Button
269+
asChild
266270
data-testid='Button-link'
267-
target='_blank'
268-
rel='noopener noreferrer'
269271
className='cursor-pointer hidden lg:flex bg-primary hover:bg-blue-700 text-white transition-all duration-500 ease-in-out rounded-md px-3 text-sm font-medium tracking-heading py-2.5 ml-2'
270-
href='https://github.com/json-schema-org/json-schema-spec'
271272
>
272-
<span className='inline-block mr-2'>
273-
<svg
274-
className='inline-block -mt-1 w-6 h-6'
275-
fill='currentColor'
276-
viewBox='0 0 24 24'
277-
>
278-
<path
279-
fillRule='evenodd'
280-
d='M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z'
281-
clipRule='evenodd'
282-
></path>
283-
</svg>
284-
</span>
285-
<span className='inline-block'>Star on GitHub</span>
286-
</a>
273+
<a
274+
target='_blank'
275+
rel='noopener noreferrer'
276+
href='https://github.com/json-schema-org/json-schema-spec'
277+
>
278+
<span className='inline-block mr-1'>
279+
<svg
280+
className='inline-block -mt-1 w-6 h-6 size-7'
281+
fill='currentColor'
282+
viewBox='0 0 24 24'
283+
>
284+
<path
285+
fillRule='evenodd'
286+
d='M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z'
287+
clipRule='evenodd'
288+
></path>
289+
</svg>
290+
</span>
291+
<span className='inline-block'>Star on GitHub</span>
292+
</a>
293+
</Button>
287294
</div>
288295
</div>
289296
);

cypress/components/Headlines.cy.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ describe('Headlines Component', () => {
8383
mockRouter.push('/#what-is-json-schema');
8484

8585
// Check if the headline is active
86-
cy.get('span').should(
87-
'have.class',
88-
'text-startBlue dark:text-endBlue inline-block ml-2',
89-
);
86+
cy.get('span').should('have.class', 'text-startBlue inline-block ml-2');
9087
cy.get('span').should('have.text', '¶');
9188
});
9289

@@ -99,10 +96,7 @@ describe('Headlines Component', () => {
9996

10097
// Check if Correct headline is active
10198
cy.mount(<Headline1>What is JSON Schema?</Headline1>);
102-
cy.get('span').should(
103-
'have.class',
104-
'text-startBlue dark:text-endBlue inline-block ml-2',
105-
);
99+
cy.get('span').should('have.class', 'text-startBlue inline-block ml-2');
106100
cy.get('span').should('have.text', '¶');
107101
});
108102
});

0 commit comments

Comments
 (0)