2.11.13 • Published 7 days ago

@gewest13/shared v2.11.13

Weekly downloads
-
License
-
Repository
github
Last release
7 days ago

Gewest13 components

Gewest13 Library Shared Components is a curated repository of reusable UI assets used by Gewest13. Designed to enhance development efficiency and promote consistency, these components serve as valuable resources for streamlining application creation.

Table of Contents

  1. Components

  2. Hooks

  3. Functions

  4. Utils

  5. All CSS imports

Components

Components can be imported individually, or you have the option to import all components at once using the root file index.js. Additionally, you can include the main CSS file named index.css, which is situated within @gewest13/components/dist/index.css. However, for optimal organization, it is recommended to import each CSS file separately for the specific components you are utilizing.

ColumnsContainer

Recommended import:

import { ColumnsContainer } from '@gewest13/components';

Css import:

import '@gewest13/components/dist/ColumnsContainer.css';

Example:

<ColumnsContainer
  // Optionally, specify a custom grid container
  Container={Container}
  // Define the columns in your grid layout
  columns={[
    {
      // Define the grid columns for different screen sizes
      grids: { 
        desktop: { column: '3 / 5' }, 
        tablet: { column: '3 / 5' }, 
        mobile: { column: '4 / -4' }
      },
      // Specify the component to render inside the column
      component: (
        <Typography mobileMargin={[0, 0, 40, 0]} size="typo-24" tag="h3">
          {heading}
        </Typography>
      ),
    }
  ]}
/>

Image

Recommended import:

import { Image } from '@gewest13/components';

Css import:

import '@gewest13/components/dist/Image.css';

Recommended use:

// src/shared/Image/Image.tsx
import React from 'react';

import { Image as SharedImage } from '@gewest13/components/dist/Image';

import { vwsizes } from 'config';

export default function Image(props: React.ComponentProps<typeof SharedImage>) {
  return (
    <SharedImage
      vwSizes={vwsizes}
      {...props}
    />
  );
}

Example:

<Image
  src={{
    desktop: { mediaItemUrl: 'placeholder.jpg', altText: 'placeholder' },
    tablet: { mediaItemUrl: 'placeholder.jpg', altText: 'placeholder' },
    mobile: { mediaItemUrl: 'placeholder.jpg', altText: 'placeholder' },
  }}
  ratios={{ desktop: [1680, 1800], tablet: [840, 900], mobile: [432, 720] }}
/>

RecaptchaV3

Recommended import:

import { RecaptchaV3, getToken } from '@gewest13/components';

Example:

// Recaptcha is the recaptcha site key from the google recaptcha admin
<RecaptchaV3 recaptcha={recaptcha} />

SharedForm

Recommended import:

import { SharedForm } from '@gewest13/components';

Important:

⚠️ To use this shared form you should first import the wpMail function.

Example:

<SharedForm
  // Best practice to spread props from wordpress
  Container={<form className="example" />}
  confirmationSubject="Confirmation Subject"
  confirmationPreviewText="Confirmation Preview Text"
  // Or render a template on the server on build
  confirmationEmail="<p>Hey {{firstName}}</p>"
  dataReceiverSubject="Data Receiver Subject"
  dataReceiverPreviewText="Data Receiver Preview Text"
  dataReceiverEmail="<p>First name: {{firstName}}</p>"
  mailReceiver={[{databaseId: 3, databaseId: 2, databaseId: 1}]}
  mailSender={{ databaseId: 4 }}
  recaptcha_site_key={recaptcha}
  onSubmit={handleFormSubmit}
  onSuccessfulSubmit={handleSuccessfulSubmit}
  onFailedSubmit={handleFailedSubmit}
  debug={true}
>
  <label htmlFor="textInput">
    Enter Text:
    <input
      type="text"
      id="textInput"
      value=""
    />
  </label>
  {/* Add other form elements as needed */}
</SharedForm>

Swiper

Recommended import:

import { Swiper, SwiperCard } from '@gewest13/components';

Css import:

import '@gewest13/components/dist/Swiper.css';

Example:

<SharedSwiper>
  {slides && slides.map((slide, index) => (
    // Add width and height here
    <SwiperCard className={styles.slideCard} key={index}>
      {slide}
    </SwiperCard>
  ))}
</SharedSwiper>

Video

Recommended import:

import { Video, VideoComponent, FullVideo } from '@gewest13/components';

Css import:

import '@gewest13/components/dist/Video.css';

Example:

<Video
  src={{mediaItemUrl: 'placeholder.jpg', altText: 'placeholder'}}
  ratio={[1600, 900]}
/>  

<VideoComponent
  src={{
    desktop: { mediaItemUrl: 'placeholder.jpg', altText: 'placeholder' },
    tablet: { mediaItemUrl: 'placeholder.jpg', altText: 'placeholder' },
    mobile: { mediaItemUrl: 'placeholder.jpg', altText: 'placeholder' },
  }}
  ratios={{ desktop: [1680, 1800], tablet: [840, 900], mobile: [432, 720] }}
/>

<FullVideo 
  ref={videoRef} 
  disableFullScreenHandling 
  srcFull={fullVideo} 
  className={styles.video} 
  ratios={{ desktop: [1680, 945] }} 
  src={{ desktop: videoLoop }}
>
  {fullVideo && (
    <button onClick={() => videoRef.current.playFullScreen()}>Play movie</button>
  )}
</FullVideo>

SharedTypography

Example:

'use client';

import React, { forwardRef, ForwardedRef } from 'react';

import { SharedTypography, TypographyImperativeHandle } from '@gewest13/components/dist/SharedTypography';

import { vwsizes } from 'config';

import styles from './Typography.module.scss';

export interface TTypography {
  size: TfontSizes;
  className?: string;
}

const Typography = forwardRef((props: React.ComponentProps<typeof SharedTypography> & TTypography, ref: ForwardedRef<TypographyImperativeHandle>) => {
  const { className, size, ...rest } = props;

  return (
    <SharedTypography
      {...rest}
      ref={ref}
      className={`${styles[`typography--${size}`]} ${className || ''}`}
      vwSizes={vwsizes}
    />
  );
});

export default Typography;

Hooks

useWindowSize

Description for the useWindowSize hook.

Functions

createContainer

Description for the createContainer function.

draftModeWordpress

Recommended import:

import { draftModeWordpress } from '@gewest13/components';

Example:

// Path: app/api/preview/route.ts
import { WORDPRESS_API_URL } from 'config';
import { draftModeWordpress } from '@gewest13/components';

export async function GET(req: any) {
  // When going to /api/preview?uri=1234
  // uri should be the databaseId of the post
  return draftModeWordpress({
    req,
    api_url: WORDPRESS_API_URL,
  });
}
// Path: inside the root on app level ~/middleware.ts
import { NextRequest, NextResponse } from 'next/server';

export const config = {
  matcher: ['/api/preview'],
};

export async function middleware(req: NextRequest) {
  const basicAuth = req.headers.get('authorization');
  const url = req.nextUrl;

  if (basicAuth) {
    const authValue = basicAuth.split(' ')[1];
    const [user, pwd] = atob(authValue).split(':');

    return NextResponse.rewrite(`${url}&username=${user}&password=${encodeURIComponent(pwd)}`);
  }

  return NextResponse.rewrite(url, { status: 401 });
}
// Path src/components/LivePreview/LivePreview.tsx
// This also should be a shared component
'use client';

import React, { Suspense, startTransition, useEffect, useState } from 'react';

import getPage from '@/lib/get-page';

import Components from '@/shared/Components/Components';
import Hero from '@/shared/Hero/Hero';

function getCookie(name: string) {
  const nameEQ = `${name}=`;
  const ca = document.cookie.split(';');
  // eslint-disable-next-line no-plusplus
  for (let i = 0; i < ca.length; i++) {
    let c = ca[i];
    while (c.charAt(0) === ' ') c = c.substring(1, c.length);
    if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
  }
  return null;
}

export default function LivePreview(data: any) {
  const [draftData, setDraftData] = useState(null) as any;
  const { draftMode, id } = data;
  const { acfComponents, acfHero } = draftData || data;

  useEffect(() => {
    if (!draftMode) return undefined;

    const authToken = getCookie('token');

    if (!authToken) return undefined;

    const intervalId = setInterval(async () => {
      const pageData = await getPage({ id });

      startTransition(() => {
        setDraftData(pageData);
      });
    }, 2000);

    return () => {
      clearInterval(intervalId);
    };
  }, []);

  return (
    <Suspense fallback={null}>
      <Hero acfHero={acfHero} />
      <Components acfComponents={acfComponents} />
    </Suspense>
  );
}

fetchWordpress

Description for the fetchWordpress function.

grid

Description for the grid function.

margin

Description for the margin function.

ratios

Description for the ratios function.

vwsize

Description for the vwsize function.

wpMail

Recommended import:

import { wpMail } from '@gewest13/components';

Example:

// Path: app/api/mail/route.ts
import { WORDPRESS_API_URL } from 'config';
import { testWpMail, postWpMail } from '@gewest13/components';

export async function GET(req: any) {
  return testWpMail({
    req,
    api_url: WORDPRESS_API_URL,
    // NEVER EXPOSE THIS IN
    wordpress_username: process.env.WORDPRESS_USERNAME!,
    wordpress_password: process.env.WORDPRESS_PASSWORD!,
  });
}

export async function POST(req: any) {
  return postWpMail({
    req,
    api_url: WORDPRESS_API_URL,
    wordpress_username: process.env.WORDPRESS_USERNAME!,
    wordpress_password: process.env.WORDPRESS_PASSWORD!,
  });
}

Utils

lerp

Description

CSS

Comment out not needed css imports inside layout or app

import '@gewest13/components/dist/ColumnsContainer/ColumnsContainer.css';
import '@gewest13/components/dist/Image/Image.css';
import '@gewest13/components/dist/SharedFormConfirmation/SharedFormConfirmation.css';
import '@gewest13/components/dist/Swiper/Swiper.css';
import '@gewest13/components/dist/Video/Video.css';
2.11.12

7 days ago

2.11.13

7 days ago

2.12.0-beta.0.2

7 days ago

2.12.0-beta.0.3

7 days ago

2.12.0-beta.0.4

7 days ago

2.12.0-beta.0.5

7 days ago

2.11.8

9 days ago

2.11.9

9 days ago

2.11.6

11 days ago

2.11.7

11 days ago

2.11.10

9 days ago

2.11.11

9 days ago

2.12.0-beta.0.1

15 days ago

2.11.4

14 days ago

2.11.5

14 days ago

2.11.2

15 days ago

2.11.3

14 days ago

2.11.0

19 days ago

2.11.1

19 days ago

2.10.7-beta.0.2

19 days ago

2.10.7-beta.0.1

19 days ago

2.10.7

21 days ago

2.10.6

21 days ago

2.10.5

27 days ago

2.10.3

27 days ago

2.10.4

27 days ago

2.10.2

28 days ago

2.10.1

1 month ago

2.9.9

1 month ago

2.9.6

1 month ago

2.9.8

1 month ago

2.9.7

1 month ago

2.8.0-beta.0.8

1 month ago

2.8.0-beta.0.7

1 month ago

2.8.0-beta.0.6

1 month ago

2.10.0

1 month ago

2.8.0-beta.0.5

1 month ago

2.8.0-beta.0.9

1 month ago

2.8.0-beta.0.4

1 month ago

2.8.0-beta.0.3

1 month ago

2.9.2

1 month ago

2.9.1

1 month ago

2.9.4

1 month ago

2.9.3

1 month ago

2.9.5

1 month ago

2.9.0

1 month ago

2.8.1

1 month ago

2.8.0

1 month ago

2.8.2

1 month ago

2.7.13

1 month ago

2.7.11

1 month ago

2.7.12

1 month ago

2.8.0-beta.0

2 months ago

2.7.9

2 months ago

2.8.0-beta.0.2

2 months ago

2.8.0-beta.0.1

2 months ago

2.7.10

2 months ago

2.7.7

2 months ago

2.7.6

2 months ago

2.2.1

4 months ago

2.2.0

4 months ago

2.4.1

4 months ago

2.2.3

4 months ago

2.4.0

4 months ago

2.2.2

4 months ago

2.6.1

3 months ago

2.4.3

4 months ago

2.2.5

4 months ago

2.6.0

3 months ago

2.4.2

4 months ago

2.2.4

4 months ago

2.6.3

3 months ago

2.2.7

4 months ago

2.6.2

3 months ago

2.4.4

4 months ago

2.2.6

4 months ago

2.0.0

4 months ago

2.7.4

3 months ago

2.5.6

4 months ago

2.3.8

4 months ago

2.7.3

3 months ago

2.5.5

4 months ago

2.3.7

4 months ago

2.5.8

4 months ago

2.7.5

3 months ago

2.5.7

4 months ago

2.3.9

4 months ago

2.5.9

4 months ago

2.5.18

4 months ago

2.5.19

3 months ago

2.5.14

4 months ago

2.5.15

4 months ago

2.5.16

4 months ago

2.5.17

4 months ago

2.5.10

4 months ago

2.5.11

4 months ago

2.5.12

4 months ago

2.5.13

4 months ago

2.5.29

3 months ago

2.3.0

4 months ago

2.5.0

4 months ago

2.3.2

4 months ago

2.3.1

4 months ago

2.7.0

3 months ago

2.5.25

3 months ago

2.5.2

4 months ago

2.3.4

4 months ago

2.5.26

3 months ago

2.5.1

4 months ago

2.3.3

4 months ago

2.7.2

3 months ago

2.5.27

3 months ago

2.5.4

4 months ago

2.3.6

4 months ago

2.7.1

3 months ago

2.5.28

3 months ago

2.5.3

4 months ago

2.3.5

4 months ago

2.5.21

3 months ago

2.5.22

3 months ago

2.5.23

3 months ago

2.5.24

3 months ago

2.1.0

4 months ago

2.5.20

3 months ago

1.1.0

5 months ago

1.0.0

5 months ago

0.1.10

5 months ago

0.1.11

5 months ago

0.1.12

5 months ago

0.1.13

5 months ago

0.1.14

5 months ago

0.1.8

5 months ago

0.1.7

5 months ago

0.1.9

5 months ago

0.1.4

5 months ago

0.1.6

5 months ago

0.1.5

5 months ago

0.1.3

5 months ago

0.1.2

5 months ago

0.1.1

5 months ago

0.1.0

5 months ago