├── globals.d.ts ├── .github └── workflows │ ├── npm-publish.yml │ ├── npm-version.yml │ ├── dependabot.yml │ └── codeql-analysis.yml ├── .babelrc ├── src ├── tests │ ├── SetupTests.ts │ └── ServerSideRedering.test.tsx ├── babel.config.js ├── hooks │ ├── useBlankSpace.tsx │ ├── useArray.tsx │ ├── useLastCard.tsx │ ├── useCarousel.tsx │ ├── useGetMedium.tsx │ └── useIsVisible.tsx ├── index.tsx ├── utils │ ├── fetchMedium.ts │ └── htmlStructure.ts ├── style │ ├── List.module.css │ ├── Label.module.css │ ├── index.css │ ├── Carousel.module.css │ ├── Card.module.css │ └── RectangularCard.module.css ├── mocks │ ├── cardData.tsx │ └── server.tsx ├── components │ ├── Label.tsx │ ├── List.tsx │ ├── Card.tsx │ ├── RectangularCard.tsx │ └── Carousel.tsx ├── stories │ ├── Card.stories.tsx │ ├── RectangularCard.stories.tsx │ ├── Label.stories.tsx │ ├── List.stories.tsx │ └── Carousel.stories.tsx └── interface │ └── interface.ts ├── .storybook ├── preview.js └── main.js ├── .gitpod.yml ├── jest.config.js ├── .gitignore ├── tsconfig.json ├── rollup.config.js ├── LICENSE ├── package.json ├── README.md └── dist ├── index.esm.js └── index.cjs.js /globals.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.css'; -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | - name: NPM Publish 2 | uses: JS-DevTools/npm-publish@v1 3 | -------------------------------------------------------------------------------- /.github/workflows/npm-version.yml: -------------------------------------------------------------------------------- 1 | - name: NPM-Version 2 | uses: Reedyuk/NPM-Version@1.1.1 3 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/env", 3 | ["@babel/preset-react", {"runtime": "automatic"}] 4 | ] 5 | } -------------------------------------------------------------------------------- /src/tests/SetupTests.ts: -------------------------------------------------------------------------------- 1 | import server from '../mocks/server' 2 | beforeAll(() => server.listen({ onUnhandledRequest: "bypass" })) 3 | afterAll(() => server.close()) -------------------------------------------------------------------------------- /src/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | ['@babel/preset-env', {targets: {node: 'current'}}], 4 | '@babel/preset-typescript', 5 | ], 6 | }; -------------------------------------------------------------------------------- /.storybook/preview.js: -------------------------------------------------------------------------------- 1 | export const parameters = { 2 | actions: { argTypesRegex: "^on[A-Z].*" }, 3 | controls: { 4 | matchers: { 5 | color: /(background|color)$/i, 6 | date: /Date$/, 7 | }, 8 | } 9 | } -------------------------------------------------------------------------------- /src/hooks/useBlankSpace.tsx: -------------------------------------------------------------------------------- 1 | function useBlankSpace(tagArray: any[]){ 2 | const tags = tagArray.map((item: string, index: number) => item.concat(' ')) 3 | 4 | return { 5 | tags 6 | } 7 | } 8 | 9 | export default useBlankSpace -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import Carousel from "./components/Carousel"; 2 | import List from "./components/List"; 3 | import Label from "./components/Label"; 4 | import fetchMedium from './utils/fetchMedium'; 5 | 6 | export { 7 | Carousel, 8 | List, 9 | Label, 10 | fetchMedium 11 | } -------------------------------------------------------------------------------- /src/hooks/useArray.tsx: -------------------------------------------------------------------------------- 1 | function useArray(){ 2 | function array(array: any[] = []){ 3 | const isEmpty = (array.length === 0)? true : false 4 | 5 | return { 6 | isEmpty 7 | } 8 | } 9 | 10 | return { 11 | array 12 | } 13 | } 14 | 15 | export default useArray -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | # This configuration file was automatically generated by Gitpod. 2 | # Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file) 3 | # and commit this file to your remote git repository to share the goodness with others. 4 | 5 | tasks: 6 | - init: yarn install 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/utils/fetchMedium.ts: -------------------------------------------------------------------------------- 1 | const axios = require('axios') 2 | 3 | async function fetchMedium(username){ 4 | const baseUrl = 'https://mediumpostsapi.vercel.app' 5 | 6 | const response = await axios.get(`${baseUrl}/api/${username}`) 7 | const data = response.data 8 | return data 9 | } 10 | 11 | export default fetchMedium -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "transform": { 3 | "^.+\\.[t|j]sx?$": "babel-jest", 4 | }, 5 | "extensionsToTreatAsEsm": [".ts", ".jsx", ".tsx"], 6 | "setupFilesAfterEnv": ["./src/tests/SetupTests.ts"], 7 | "moduleNameMapper": { 8 | "\\.(css)$": "identity-obj-proxy" 9 | }, 10 | testTimeout: 20000 11 | }; -------------------------------------------------------------------------------- /src/hooks/useLastCard.tsx: -------------------------------------------------------------------------------- 1 | function useLastCard(){ 2 | function returnLastCard(cardItem: number, dataMedium: any[], element: any){ 3 | const numberOfCards = dataMedium.length - 1 4 | const lastCard = (cardItem === numberOfCards)? element : null 5 | 6 | return lastCard 7 | } 8 | 9 | return { 10 | returnLastCard 11 | } 12 | } 13 | 14 | export default useLastCard -------------------------------------------------------------------------------- /src/style/List.module.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | font-size: 10px; 3 | } 4 | 5 | :global(a) { 6 | text-decoration: none; 7 | } 8 | 9 | .container { 10 | width: 100%; 11 | height: 100%; 12 | display: block; 13 | background: none; 14 | padding-bottom: 0.2rem 15 | } 16 | 17 | .content { 18 | display: flex; 19 | flex-direction: column; 20 | position: relative; 21 | background: #fff; 22 | gap: 1rem; 23 | } -------------------------------------------------------------------------------- /.storybook/main.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "stories": ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"], 3 | "addons": ["@storybook/addon-links", "@storybook/addon-essentials", "@storybook/addon-interactions", "@storybook/addon-controls", "@storybook/preset-create-react-app"], 4 | "framework": { 5 | name: "@storybook/react-webpack5", 6 | options: {} 7 | }, 8 | docs: { 9 | autodocs: true 10 | } 11 | }; -------------------------------------------------------------------------------- /src/style/Label.module.css: -------------------------------------------------------------------------------- 1 | .container { 2 | align-items: flex-start; 3 | display: flex; 4 | flex-direction: column; 5 | gap: 1rem; 6 | height: 0px auto; 7 | max-width: 100%; 8 | } 9 | 10 | .title { 11 | font-size: 2.4rem; 12 | color: #53565b; 13 | font-family: Roboto, sans-serif; 14 | } 15 | 16 | @media (max-width: 717px) { 17 | .container { 18 | align-items: center; 19 | } 20 | } -------------------------------------------------------------------------------- /src/utils/htmlStructure.ts: -------------------------------------------------------------------------------- 1 | const html = (component) =>` 2 | 3 | 4 | 5 | 6 | 7 | Component SSR 8 | 9 | 10 |
11 | ${component} 12 |
13 | 14 | ` 15 | 16 | export default html -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | 13 | 14 | #paths 15 | /build 16 | 17 | # misc 18 | .DS_Store 19 | .env.local 20 | .env.development.local 21 | .env.test.local 22 | .env.production.local 23 | 24 | npm-debug.log* 25 | yarn-debug.log* 26 | yarn-error.log* 27 | -------------------------------------------------------------------------------- /src/mocks/cardData.tsx: -------------------------------------------------------------------------------- 1 | const cardData = { 2 | title: "Por que usar TypeScript?", 3 | date: "2020-09-24", 4 | image: "https://cdn-images-1.medium.com/max/1024/1*ODf4X51nKEMElimXA706gQ.jpeg", 5 | description: "Veja quais são os benefícios de utiliza-lo em seus projetos", 6 | tags: [ 7 | "ecmascript-2020", 8 | "typescript", 9 | "ecmascript-6", 10 | "javascript", 11 | "ecmascript" 12 | ] 13 | } 14 | 15 | export default cardData -------------------------------------------------------------------------------- /src/components/Label.tsx: -------------------------------------------------------------------------------- 1 | import { LabelProps } from '../interface/interface' 2 | 3 | import styles from '../style/Label.module.css' 4 | 5 | function Label({text = 'Medium Articles', children}: LabelProps){ 6 | return ( 7 |
8 | { text } 9 | { 10 | children 11 | } 12 |
13 | ) 14 | } 15 | 16 | export default Label -------------------------------------------------------------------------------- /src/style/index.css: -------------------------------------------------------------------------------- 1 | body, div, span { 2 | margin: 0; 3 | font-family: 'Roboto', sans-serif; 4 | -webkit-font-smoothing: antialiased; 5 | -moz-osx-font-smoothing: grayscale; 6 | font-size: 10px; 7 | } 8 | 9 | *, a, h1, h2, h3, h4, h5, h6, p, span { 10 | font-family: Roboto, sans-serif; 11 | } 12 | 13 | a { 14 | text-decoration: none; 15 | } 16 | 17 | code { 18 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 19 | monospace; 20 | } -------------------------------------------------------------------------------- /src/stories/Card.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Card from '../components/Card' 3 | import cardData from '../mocks/cardData' 4 | 5 | 6 | // eslint-disable-next-line import/no-anonymous-default-export 7 | export default { 8 | component: Card 9 | } 10 | 11 | export const Basic = (args) => 12 | 13 | Basic.args = { 14 | userdata: cardData, 15 | options: { 16 | borderRadius: true, 17 | showTags: false, 18 | showDate: false 19 | } 20 | } -------------------------------------------------------------------------------- /src/stories/RectangularCard.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import RectangularCard from '../components/RectangularCard' 3 | import cardData from "../mocks/cardData"; 4 | 5 | // eslint-disable-next-line import/no-anonymous-default-export 6 | export default { 7 | component: RectangularCard 8 | } 9 | 10 | export const Basic = (args) => 11 | 12 | Basic.args = { 13 | userdata: cardData, 14 | options: { 15 | borderRadius: false, 16 | showTags: true, 17 | showDate: true 18 | } 19 | } -------------------------------------------------------------------------------- /.github/workflows/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "weekly" 12 | -------------------------------------------------------------------------------- /src/hooks/useCarousel.tsx: -------------------------------------------------------------------------------- 1 | import { useState } from 'react' 2 | 3 | function useCarousel(){ 4 | const [ position, setPosition ] = useState(0) 5 | 6 | const displacement = 19 7 | 8 | function moveForward(cardIsVisible: boolean) { 9 | if(!cardIsVisible){ 10 | setPosition(position + displacement) 11 | } 12 | } 13 | 14 | function moveBack() { 15 | if(position > 0){ 16 | setPosition(position - displacement) 17 | } 18 | } 19 | 20 | return { 21 | position, 22 | moveForward, 23 | moveBack, 24 | } 25 | 26 | } 27 | 28 | export default useCarousel -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "declarationDir": "build", 5 | "module": "esnext", 6 | "target": "es5", 7 | "lib": ["es6", "dom", "es2016", "es2017"], 8 | "sourceMap": true, 9 | "jsx": "react-jsx", 10 | "moduleResolution": "node", 11 | "allowSyntheticDefaultImports": true, 12 | "esModuleInterop": true 13 | }, 14 | "include": ["src/**/*", "globals.d.ts"], 15 | "exclude": [ 16 | "node_modules", 17 | "build", 18 | "dist", 19 | "src/stories/**/*", 20 | "src/tests/**/*", 21 | "src/mocks/**/*", 22 | ".storybook", 23 | ] 24 | } -------------------------------------------------------------------------------- /src/stories/Label.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Label from '../components/Label' 3 | import Carousel from '../components/Carousel' 4 | import List from '../components/List' 5 | 6 | // eslint-disable-next-line import/no-anonymous-default-export 7 | export default { 8 | component: Label 9 | } 10 | 11 | export const WrapCarousel = (args)=> 12 | export const WrapList = (args)=> 13 | 14 | WrapCarousel.args = { 15 | text: 'Medium Articles' 16 | } 17 | 18 | WrapList.args = { 19 | text: 'Medium Articles' 20 | } -------------------------------------------------------------------------------- /src/hooks/useGetMedium.tsx: -------------------------------------------------------------------------------- 1 | import { useState, useEffect } from 'react'; 2 | import useArray from './useArray'; 3 | import fetchMedium from '../utils/fetchMedium'; 4 | 5 | function useGetMedium(username?: string, ssr?: boolean){ 6 | const [dataMedium, setDataMedium]:Array = useState([]); 7 | const { array } = useArray() 8 | 9 | useEffect(() => { 10 | if(!array(dataMedium).isEmpty || ssr){ 11 | return; 12 | } 13 | (async()=>{ 14 | const data = await fetchMedium(username) 15 | setDataMedium(data.dataMedium) 16 | })() 17 | }, [fetchMedium]); 18 | 19 | return dataMedium 20 | 21 | } 22 | 23 | export default useGetMedium -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import babel from '@rollup/plugin-babel'; 2 | import external from 'rollup-plugin-peer-deps-external'; 3 | import del from 'rollup-plugin-delete'; 4 | import pkg from './package.json'; 5 | import typescript from "rollup-plugin-typescript2"; 6 | import styles from "rollup-plugin-styles"; 7 | 8 | // eslint-disable-next-line import/no-anonymous-default-export 9 | export default { 10 | input: pkg.source, 11 | output: [ 12 | { file: pkg.main, format: 'cjs' }, 13 | { file: pkg.module, format: 'esm' } 14 | ], 15 | plugins: [ 16 | external(), 17 | babel({ 18 | exclude: 'node_modules/**', 19 | babelHelpers: 'bundled' 20 | }), 21 | del({ targets: ['dist/*'] }), 22 | typescript({ useTsconfigDeclarationDir: true }), 23 | styles({ modules: true }) 24 | ], 25 | external: Object.keys(pkg.peerDependencies || {}), 26 | }; -------------------------------------------------------------------------------- /src/interface/interface.ts: -------------------------------------------------------------------------------- 1 | interface Options { 2 | options?: { 3 | borderRadius?: boolean, 4 | showTags?: boolean, 5 | showDate?: boolean, 6 | openInNewTab?: boolean, 7 | ssr?: boolean 8 | } 9 | } 10 | 11 | interface User { 12 | username: string 13 | } 14 | 15 | interface Medium { 16 | dataMedium: { 17 | dataMedium: any 18 | } 19 | } 20 | 21 | interface Props { 22 | username?: User["username"], 23 | dataMedium?: Medium["dataMedium"], 24 | options?: Options["options"], 25 | } 26 | 27 | interface UserData { 28 | data: { 29 | title: string, 30 | date: string, 31 | image: string, 32 | description: string, 33 | tags: Array 34 | } 35 | } 36 | 37 | interface CardProps { 38 | userdata: UserData["data"], 39 | options?: Options["options"] 40 | } 41 | 42 | interface LabelProps { 43 | text?: string, 44 | children: JSX.Element 45 | } 46 | 47 | export { 48 | Props, 49 | Options, 50 | User, 51 | CardProps, 52 | LabelProps 53 | } -------------------------------------------------------------------------------- /src/style/Carousel.module.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | font-size: 10px; 3 | } 4 | 5 | :global(a) { 6 | text-decoration: none; 7 | } 8 | 9 | .container { 10 | width: 100%; 11 | height: 100%; 12 | min-height: 25rem; 13 | max-height: 40rem; 14 | display: block; 15 | background: none; 16 | overflow-x: hidden; 17 | padding-bottom: 0.2rem 18 | } 19 | 20 | .content { 21 | display: flex; 22 | position: relative; 23 | background: #fff; 24 | gap: 1rem; 25 | } 26 | 27 | .carouselButton { 28 | width: 4.0rem; 29 | height: 4.0rem; 30 | border-radius: 100%; 31 | display: flex; 32 | justify-content: center; 33 | align-items: center; 34 | position: relative; 35 | z-index: 1; 36 | border: 0; 37 | background: rgba(0,0,0,.5); 38 | opacity: 1; 39 | } 40 | 41 | .previousButton { 42 | margin-left: 0.5%; 43 | float: left; 44 | top: 11.4rem; 45 | } 46 | 47 | .nextButton { 48 | float: right; 49 | right: 1rem; 50 | top: -13.7rem; 51 | } 52 | 53 | .iconButton > :local(polyline) { 54 | stroke: #fff; 55 | } -------------------------------------------------------------------------------- /src/components/List.tsx: -------------------------------------------------------------------------------- 1 | import { Props } from '../interface/interface' 2 | import RectangularCard from './RectangularCard'; 3 | import useGetMedium from '../hooks/useGetMedium'; 4 | 5 | import styles from '../style/List.module.css' 6 | 7 | function List({ username = '', dataMedium, options = {} }: Props){ 8 | const ssr = options?.ssr || false 9 | const data = useGetMedium(username, ssr) 10 | const medium = (ssr)? dataMedium?.dataMedium : data 11 | const openInNewTab = (options.hasOwnProperty('openInNewTab'))? options.openInNewTab : true 12 | const nameTarget = (openInNewTab)? '_blank' : '_self' 13 | 14 | return ( 15 |
16 | 17 | { 18 | medium.map((item: any, index: number) => ( 19 | 20 | 21 | 22 | )) 23 | } 24 | 25 |
26 | ) 27 | } 28 | 29 | export default List -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 David Fernando 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /src/hooks/useIsVisible.tsx: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react" 2 | 3 | function useIsVisible(container: any, element: any){ 4 | const [ isVisible, setIsVisible ] = useState(false) 5 | const [ elementPosition, setElementPosition ] = useState(0) 6 | const [ containerWidth, setContainerWidth ] = useState(0) 7 | 8 | const elementDefaultValue = { x: 0 } 9 | const containerDefaultValue = { width: 0 } 10 | const timeInMiliseconds = 20 11 | const excess = 110 12 | 13 | setTimeout(()=>{ 14 | const { x } = element.current?.getBoundingClientRect?.() || elementDefaultValue 15 | setElementPosition(x) 16 | const { width } = container.current?.getBoundingClientRect?.() || containerDefaultValue 17 | setContainerWidth(width) 18 | }, timeInMiliseconds) 19 | 20 | useEffect(()=>{ 21 | determineIfElementIsVisible() 22 | // eslint-disable-next-line 23 | }, [elementPosition]) 24 | 25 | function determineIfElementIsVisible(){ 26 | const isElementVisible = (elementPosition + excess < containerWidth)? true : false 27 | 28 | setIsVisible(isElementVisible) 29 | } 30 | 31 | return isVisible 32 | } 33 | 34 | export default useIsVisible -------------------------------------------------------------------------------- /src/stories/List.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import List from "../components/List"; 3 | 4 | // eslint-disable-next-line import/no-anonymous-default-export 5 | export default { 6 | component: List 7 | } 8 | 9 | const options = { 10 | borderRadius: false, 11 | showTags: true, 12 | showDate: true, 13 | openInNewTab: true, 14 | } 15 | 16 | function Container({ children }){ 17 | const container = { 18 | width: '100%', 19 | display: 'flex', 20 | justifyContent: 'center' 21 | } 22 | 23 | const content = { 24 | width: '80%', 25 | height: 'max-content', 26 | } 27 | 28 | return ( 29 |
30 |
31 | { 32 | children 33 | } 34 |
35 |
36 | ) 37 | } 38 | 39 | export const Basic = (args) => 40 | 41 | Basic.args = { 42 | username: "alex.streza", 43 | options, 44 | dataMedium: { disable: true } 45 | } 46 | 47 | export const Contained = () => 48 | 49 | export const Placeholder = (args) => 50 | 51 | Placeholder.args = { 52 | username: "getmehiredbootcamp", 53 | options, 54 | dataMedium: { disable: true } 55 | } 56 | -------------------------------------------------------------------------------- /src/stories/Carousel.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Carousel from "../components/Carousel"; 3 | 4 | // eslint-disable-next-line import/no-anonymous-default-export 5 | export default { 6 | component: Carousel 7 | } 8 | 9 | function Container({ children }){ 10 | const container = { 11 | width: '100%', 12 | height: 'min-content', 13 | display: 'flex', 14 | justifyContent: 'center' 15 | } 16 | 17 | const content = { 18 | width: '80%', 19 | height: 'max-content', 20 | border: '1px #9b8f8f dashed' 21 | } 22 | 23 | return ( 24 |
25 |
26 | { 27 | children 28 | } 29 |
30 |
31 | ) 32 | } 33 | 34 | const options = { 35 | borderRadius: true, 36 | showTags: false, 37 | showDate: false, 38 | openInNewTab: true, 39 | } 40 | 41 | export const Basic = (args) => 42 | 43 | Basic.args = { 44 | username: "alex.streza", 45 | options, 46 | dataMedium: { disable: true } 47 | } 48 | 49 | export const Contained = () => 50 | 51 | export const Placeholder = (args) => 52 | 53 | Placeholder.args = { 54 | username: "getmehiredbootcamp", 55 | options, 56 | dataMedium: { disable: true } 57 | } 58 | -------------------------------------------------------------------------------- /src/style/Card.module.css: -------------------------------------------------------------------------------- 1 | .container { 2 | width: min-content; 3 | height: 100%; 4 | min-width: 25rem; 5 | max-width: 35rem; 6 | min-height: 25rem; 7 | max-height: 35rem; 8 | flex-direction: column; 9 | display: flex; 10 | background: #fff; 11 | border: 1px solid rgba(0,0,0,.2); 12 | font-size: 10px; 13 | font-family: 'Roboto', sans-serif; 14 | margin: 0; 15 | } 16 | 17 | .borderRadiusContainer { 18 | border-radius: 10px; 19 | } 20 | 21 | .thumbnail { 22 | width: 100%; 23 | height: 12.533rem; 24 | min-height: 12.533rem; 25 | max-height: 14.533rem; 26 | } 27 | 28 | .borderRadiusThumbnail { 29 | border-top-left-radius: 10px; 30 | border-top-right-radius: 10px; 31 | } 32 | 33 | .content { 34 | padding: 10px; 35 | } 36 | 37 | .title, .description, .date, .tags { 38 | font-size: 1.6rem; 39 | color: #53565b 40 | } 41 | 42 | .title { 43 | font-weight: 700; 44 | text-overflow: ellipsis; 45 | -webkit-box-orient: vertical; 46 | -webkit-line-clamp: 2; 47 | display: -webkit-box; 48 | overflow: hidden; 49 | } 50 | 51 | .description { 52 | text-align: initial; 53 | max-height: 44%; 54 | text-overflow: ellipsis; 55 | -webkit-box-orient: vertical; 56 | -webkit-line-clamp: 2; 57 | display: -webkit-box; 58 | overflow: hidden; 59 | } 60 | 61 | .date, .tags { 62 | font-size: 1.2rem; 63 | } 64 | 65 | .tags { 66 | word-spacing: 0.5rem; 67 | line-height: 1.6rem; 68 | } -------------------------------------------------------------------------------- /src/tests/ServerSideRedering.test.tsx: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | 3 | describe('Rendering test of components on the server', () => { 4 | 5 | test('Should rendering carousel on server', async() => { 6 | 7 | const classCardContainer = 'Card_module_container__bd43ad53' 8 | 9 | const test = await axios.get('http://localhost:3333/carousel') 10 | 11 | const classSelected = await test.data.match(classCardContainer)[0] 12 | 13 | expect(classSelected).toBe(classCardContainer) 14 | }) 15 | 16 | test('Should rendering list on server', async() => { 17 | 18 | const classCardContainer = 'RectangularCard_module_container__e8f8839b' 19 | 20 | const test = await axios.get('http://localhost:3333/list') 21 | 22 | const classSelected = await test.data.match(classCardContainer)[0] 23 | 24 | expect(classSelected).toBe(classCardContainer) 25 | }) 26 | 27 | test('Should rendering wrapped carousel on label', async() => { 28 | 29 | const classCardContainer = 'Label_module_container__ee32c7c2' 30 | 31 | const test = await axios.get('http://localhost:3333/wrapcarousel') 32 | 33 | const classSelected = await test.data.match(classCardContainer)[0] 34 | 35 | expect(classSelected).toBe(classCardContainer) 36 | }) 37 | 38 | test('Should rendering wrapped list on label', async() => { 39 | 40 | const classCardContainer = 'Label_module_container__ee32c7c2' 41 | 42 | const test = await axios.get('http://localhost:3333/wraplist') 43 | 44 | const classSelected = await test.data.match(classCardContainer)[0] 45 | 46 | expect(classSelected).toBe(classCardContainer) 47 | }) 48 | 49 | }) -------------------------------------------------------------------------------- /src/components/Card.tsx: -------------------------------------------------------------------------------- 1 | import classnames from 'classnames'; 2 | import useArray from '../hooks/useArray'; 3 | import useBlankSpace from '../hooks/useBlankSpace'; 4 | import { CardProps } from '../interface/interface' 5 | 6 | import styles from '../style/Card.module.css' 7 | 8 | function Card({ userdata, options = {} }: CardProps){ 9 | const { array } = useArray() 10 | 11 | const borderRadius = (options.hasOwnProperty('borderRadius'))? options.borderRadius : true 12 | const borderRadiusContainer = (borderRadius) && styles.borderRadiusContainer 13 | const borderRadiusThumbnail = (borderRadius) && styles.borderRadiusThumbnail 14 | const tagArray = (array(userdata.tags).isEmpty)? ['NoTags']: userdata.tags 15 | const { tags } = useBlankSpace(tagArray) 16 | 17 | return ( 18 |
19 | 20 | {userdata.title} 25 | 26 | 27 | { userdata.title } 28 |

29 | { userdata.description } 30 |

31 | { 32 | (options.showDate) && ( 33 |

34 | { userdata.date } 35 |

36 | ) 37 | } 38 | { 39 | (options.showTags) && ( 40 |

41 | { tags } 42 |

43 | ) 44 | } 45 |
46 |
47 | ) 48 | } 49 | 50 | export default Card -------------------------------------------------------------------------------- /src/mocks/server.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { renderToString } from 'react-dom/server' 3 | import { rest } from 'msw' 4 | import { setupServer } from 'msw/node' 5 | import html from '../utils/htmlStructure' 6 | 7 | import { Carousel, List, Label, fetchMedium } from '../../dist/index.esm.js' 8 | 9 | const handlers = [ 10 | rest.get('http://localhost:3333/carousel', async(request, response, context)=>{ 11 | 12 | const data = await fetchMedium('davidfernandodamata21') 13 | 14 | const component = renderToString( 15 | 16 | ) 17 | 18 | return response( 19 | context.xml(html(component)) 20 | ) 21 | }), 22 | 23 | rest.get('http://localhost:3333/list', async(request, response, context)=>{ 24 | 25 | const data = await fetchMedium('davidfernandodamata21') 26 | 27 | const component = renderToString( 28 | 29 | ) 30 | 31 | return response( 32 | context.xml(html(component)) 33 | ) 34 | }), 35 | 36 | rest.get('http://localhost:3333/wrapcarousel', async(request, response, context)=>{ 37 | 38 | const data = await fetchMedium('davidfernandodamata21') 39 | 40 | const component = renderToString( 41 | 44 | ) 45 | 46 | return response( 47 | context.xml(html(component)) 48 | ) 49 | }), 50 | 51 | rest.get('http://localhost:3333/wraplist', async(request, response, context)=>{ 52 | 53 | const data = await fetchMedium('davidfernandodamata21') 54 | 55 | const component = renderToString( 56 | 59 | ) 60 | 61 | return response( 62 | context.xml(html(component)) 63 | ) 64 | }) 65 | ] 66 | 67 | const server = setupServer(...handlers) 68 | 69 | export default server -------------------------------------------------------------------------------- /src/components/RectangularCard.tsx: -------------------------------------------------------------------------------- 1 | import classnames from 'classnames'; 2 | import useArray from '../hooks/useArray'; 3 | import useBlankSpace from '../hooks/useBlankSpace'; 4 | import { CardProps } from '../interface/interface' 5 | 6 | import styles from '../style/RectangularCard.module.css' 7 | 8 | function RectangularCard({ userdata, options = {} }: CardProps){ 9 | const { array } = useArray() 10 | 11 | const borderRadius = (options.hasOwnProperty('borderRadius'))? options.borderRadius : false 12 | const showDate = (options.hasOwnProperty('showDate'))? options.showDate : true 13 | const showTags = (options.hasOwnProperty('showTags'))? options.showTags : true 14 | const borderRadiusContainer = (borderRadius) && styles.borderRadiusContainer 15 | const borderRadiusThumbnail = (borderRadius) && styles.borderRadiusThumbnail 16 | const tagArray = (array(userdata.tags).isEmpty)? ['NoTags']: userdata.tags 17 | const { tags } = useBlankSpace(tagArray) 18 | 19 | return ( 20 |
21 | 22 | {userdata.title} 27 | 28 | 29 | { userdata.title } 30 |

31 | { userdata.description } 32 |

33 | 34 | { 35 | (showDate) && ( 36 |

37 | { userdata.date } 38 |

39 | ) 40 | } 41 | { 42 | (showTags) && ( 43 |

44 | { tags } 45 |

46 | ) 47 | } 48 |
49 |
50 |
51 | ) 52 | } 53 | 54 | export default RectangularCard -------------------------------------------------------------------------------- /src/components/Carousel.tsx: -------------------------------------------------------------------------------- 1 | import { useRef } from 'react'; 2 | import classnames from 'classnames'; 3 | import { GrFormPrevious, GrFormNext } from 'react-icons/gr' 4 | import { Props } from '../interface/interface' 5 | import Card from './Card' 6 | import useGetMedium from '../hooks/useGetMedium'; 7 | import useCarousel from '../hooks/useCarousel'; 8 | import useIsVisible from '../hooks/useIsVisible'; 9 | import useLastCard from '../hooks/useLastCard'; 10 | 11 | import styles from '../style/Carousel.module.css' 12 | 13 | function Carousel({ username = '', dataMedium, options = {} }: Props){ 14 | const ssr = options?.ssr || false 15 | const data = useGetMedium(username, ssr) 16 | const medium = (ssr)? dataMedium?.dataMedium : data 17 | const { moveForward, moveBack, position } = useCarousel() 18 | const openInNewTab = (options.hasOwnProperty('openInNewTab'))? options.openInNewTab : true 19 | const nameTarget = (openInNewTab)? '_blank' : '_self' 20 | const cardContainer:any = useRef() 21 | const carouselContainer:any = useRef() 22 | const cardIsVisible:boolean = useIsVisible(carouselContainer, cardContainer) 23 | const { returnLastCard } = useLastCard() 24 | 25 | 26 | return ( 27 |
28 | { 29 | (position > 0) && ( 30 | 33 | ) 34 | } 35 | 36 | { 37 | medium.map((item: any, index: number) => ( 38 | 39 | 40 | 41 | )) 42 | } 43 | 44 | { 45 | (!cardIsVisible) && ( 46 | 49 | ) 50 | } 51 |
52 | ) 53 | } 54 | 55 | export default Carousel -------------------------------------------------------------------------------- /src/style/RectangularCard.module.css: -------------------------------------------------------------------------------- 1 | .container { 2 | width: 100%; 3 | height: max-content; 4 | min-height: 19rem; 5 | display: flex; 6 | background: #fff; 7 | border: 1px solid rgba(0,0,0,.2); 8 | font-size: 10px; 9 | font-family: 'Roboto', sans-serif; 10 | margin: 0; 11 | gap: 1rem; 12 | } 13 | 14 | .borderRadiusContainer { 15 | border-radius: 10px; 16 | } 17 | 18 | .thumbnail { 19 | width: 19rem; 20 | height: 100%; 21 | min-height: 5rem; 22 | min-width: 5rem; 23 | aspect-ratio: 1/1; 24 | } 25 | 26 | .borderRadiusThumbnail { 27 | border-top-left-radius: 10px; 28 | border-bottom-left-radius: 10px 29 | } 30 | 31 | .content { 32 | padding: 10px; 33 | display: flex; 34 | flex-direction: column; 35 | flex-wrap: nowrap; 36 | gap: 0.8rem; 37 | height: max-content; 38 | max-height: 40rem; 39 | } 40 | 41 | .details { 42 | display: flex; 43 | flex-direction: column; 44 | flex-wrap: wrap; 45 | gap: 0rem; 46 | } 47 | 48 | .title, .description, .date, .tags { 49 | font-size: 1.6rem; 50 | color: #53565b 51 | } 52 | 53 | .title { 54 | font-size: 2.6rem; 55 | font-weight: 700; 56 | text-overflow: ellipsis; 57 | -webkit-box-orient: vertical; 58 | -webkit-line-clamp: 2; 59 | display: -webkit-box; 60 | } 61 | 62 | .description { 63 | font-size: 1.6rem; 64 | text-align: initial; 65 | max-height: 44%; 66 | text-overflow: ellipsis; 67 | -webkit-box-orient: vertical; 68 | -webkit-line-clamp: 2; 69 | display: -webkit-box; 70 | overflow: hidden; 71 | } 72 | 73 | .date, .tags { 74 | font-size: 1.2rem; 75 | } 76 | 77 | .tags { 78 | word-spacing: 0.5rem; 79 | line-height: 1.3rem; 80 | } 81 | 82 | @media (max-width: 890px) { 83 | .title { 84 | font-size: 1.6rem; 85 | } 86 | .description { 87 | font-size: 1.5rem; 88 | } 89 | .thumbnail { 90 | width: 18rem; 91 | height: 100%; 92 | } 93 | .content { 94 | gap: 0.5rem; 95 | height: 14rem; 96 | } 97 | } 98 | 99 | @media (max-width: 526px) { 100 | .description { 101 | overflow: visible; 102 | } 103 | .thumbnail { 104 | width: 100%; 105 | height: 24rem; 106 | } 107 | .container { 108 | flex-direction: column; 109 | height: 100%; 110 | min-height: 43rem; 111 | } 112 | .content { 113 | gap: 0rem; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ "main" ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ "main" ] 20 | schedule: 21 | - cron: '43 16 * * 4' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'javascript' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v3 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v2 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | 52 | # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 53 | # queries: security-extended,security-and-quality 54 | 55 | 56 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 57 | # If this step fails, then you should remove it and run the build manually (see below) 58 | - name: Autobuild 59 | uses: github/codeql-action/autobuild@v2 60 | 61 | # ℹ️ Command-line programs to run using the OS shell. 62 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 63 | 64 | # If the Autobuild fails above, remove it and uncomment the following three lines. 65 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 66 | 67 | # - run: | 68 | # echo "Run, Build Application using script" 69 | # ./location_of_script_within_repo/buildscript.sh 70 | 71 | - name: Perform CodeQL Analysis 72 | uses: github/codeql-action/analyze@v2 73 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mediumpostscard", 3 | "version": "2.0.5", 4 | "description": "React Isomorphic library that show your Medium articles.", 5 | "main": "dist/index.cjs.js", 6 | "module": "dist/index.esm.js", 7 | "source": "src/index.tsx", 8 | "dependencies": { 9 | "@testing-library/jest-dom": "^5.16.4", 10 | "@testing-library/react": "^13.0.0", 11 | "@testing-library/user-event": "^13.2.1", 12 | "@types/jest": "^28.1.2", 13 | "@types/node": "^18.0.0", 14 | "@types/react": "^18.0.14", 15 | "@types/react-dom": "^18.0.5", 16 | "@xmldom/xmldom": "0.8.6", 17 | "axios": "^0.27.2", 18 | "classnames": "^2.3.1", 19 | "glob-parent": "5.1.2", 20 | "json5": "2.2.3", 21 | "loader-utils": "3.2.1", 22 | "nth-check": "2.0.1", 23 | "react": "18.1.0", 24 | "react-dom": "18.1.0", 25 | "react-icons": "^4.4.0", 26 | "react-scripts": "^5.0.1", 27 | "rollup-plugin-json": "^4.0.0", 28 | "rollup-plugin-node-resolve": "^5.2.0", 29 | "semver": "7.5.2", 30 | "trim": "0.0.3", 31 | "trim-newlines": "3.0.1", 32 | "typescript": "^4.7.4", 33 | "web-vitals": "^2.1.0" 34 | }, 35 | "scripts": { 36 | "start": "react-scripts start", 37 | "build": "rollup -c", 38 | "build-watch": "rollup -c -w", 39 | "storybook": "storybook dev -p 6006", 40 | "build-storybook": "storybook build", 41 | "test": "jest ./src/tests --detectOpenHandles", 42 | "build-and-test": "yarn build && yarn test" 43 | }, 44 | "eslintConfig": { 45 | "extends": [ 46 | "react-app", 47 | "react-app/jest" 48 | ] 49 | }, 50 | "browserslist": { 51 | "production": [ 52 | ">0.2%", 53 | "not dead", 54 | "not op_mini all" 55 | ], 56 | "development": [ 57 | "last 1 chrome version", 58 | "last 1 firefox version", 59 | "last 1 safari version" 60 | ] 61 | }, 62 | "devDependencies": { 63 | "@babel/cli": "^7.17.10", 64 | "@babel/core": "^7.18.2", 65 | "@babel/preset-env": "^7.18.2", 66 | "@babel/preset-react": "^7.17.12", 67 | "@babel/preset-typescript": "^7.18.6", 68 | "@rollup/plugin-babel": "^5.3.1", 69 | "@storybook/addon-actions": "^7.0.26", 70 | "@storybook/addon-controls": "^7.0.26", 71 | "@storybook/addon-essentials": "^7.0.26", 72 | "@storybook/addon-interactions": "^7.0.26", 73 | "@storybook/addon-links": "^7.0.26", 74 | "@storybook/preset-create-react-app": "^7.0.26", 75 | "@storybook/react": "^7.0.26", 76 | "@storybook/react-webpack5": "^7.0.26", 77 | "@storybook/testing-library": "^0.2.0", 78 | "@types/webgl2": "^0.0.6", 79 | "babel-jest": "^28.1.2", 80 | "babel-loader": "^8.2.5", 81 | "identity-obj-proxy": "^3.0.0", 82 | "jest": "^28.1.2", 83 | "msw": "^0.43.1", 84 | "rollup": "^2.75.6", 85 | "rollup-plugin-delete": "^2.0.0", 86 | "rollup-plugin-peer-deps-external": "^2.2.4", 87 | "rollup-plugin-styles": "^4.0.0", 88 | "rollup-plugin-typescript2": "^0.32.1", 89 | "storybook": "^7.0.26" 90 | }, 91 | "peerDependencies": { 92 | "react": "^18.1.0", 93 | "react-dom": "^18.1.0" 94 | }, 95 | "repository": { 96 | "type": "git", 97 | "url": "https://github.com/david-fernando/medium-posts-card.git", 98 | "directory": "packages/name" 99 | }, 100 | "bugs": { 101 | "url": "https://github.com/david-fernando/medium-posts-card/issues" 102 | }, 103 | "homepage": "https://github.com/david-fernando/medium-posts-card", 104 | "keywords": [ 105 | "Medium Posts Card", 106 | "MediumPostsCard", 107 | "Medium Post Card", 108 | "Medium React Card", 109 | "React", 110 | "React JS", 111 | "React library", 112 | "ReactLibrary", 113 | "BibliotecaReact", 114 | "JavaScript", 115 | "JavaScript library", 116 | "Biblioteca JavaScript" 117 | ], 118 | "author": "davidfernando", 119 | "license": "MIT" 120 | } 121 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Medium Posts Card 4 |

5 | 6 |

Medium Posts Card

7 | 8 |
9 |

React Isomorphic library that show your Medium articles. 10 |
11 |

12 | 13 | [![CSR](https://img.shields.io/badge/Client%20Side%20Rendering-Supported-green)]() [![SSR](https://img.shields.io/badge/Server%20Side%20Rendering-Supported-green)]() [![Licence](https://img.shields.io/github/license/david-fernando/medium-posts-card)]() 14 |
15 | 16 | --- 17 | 18 | ## 📝 Table of Contents 19 | 20 | - [About](#about) 21 | - [Install](#install) 22 | - [Components](#components) 23 | - [Server Side Rendering](#server_side_rendering) 24 | - [How to contribute](#how_to_contribute) 25 | - [More](#more) 26 | - [Author](#authors) 27 | 28 | ## About 29 | 30 | Are you looking for a React library to display your medium posts that render both the client side and on the server side? So you are in the right place! **Medium Posts Card** get your medium articles, and displays them on your website through an easy to use component. 31 | Just download and use, as simple as that. 32 | 33 | ## Install 34 | 35 | Install this library with one of the commands below 36 | 37 | ```bash 38 | yarn add mediumpostscard 39 | 40 | //or 41 | 42 | npm install mediumpostscard 43 | ``` 44 | 45 | ## Components 46 | 47 | ### Carousel 48 | 49 | -

Describe

50 | Shows a Carousel with your Medium articles 51 | 52 | -

Screenshot

53 | Medium Posts Card Carousel Preview 54 | 55 | -

Basic usage (with example)

56 | 57 | ```javascript 58 | import { Carousel } from 'mediumpostscard' 59 | 60 | function Example(){ 61 | return ( 62 | 63 | ) 64 | } 65 | 66 | export default Example 67 | ``` 68 | 69 | -

Valid Props

70 | 71 | | Prop name | Description | Type | Default | 72 | | ---------- | :-----------------------------------------------: | -----------: | ------------:| 73 | | usernane | Sets your Medium username | _String_ | _underfined_ 74 | | dataMedium | Set data Medium (_only_ to Server Side Rendering) | _Object_ | _underfined_ 75 | | options | Object with options | _Object_ | _Object_| 76 | 77 | -

Valid Options

78 | 79 | | Option | Description | Type | Default | 80 | | -------------| :------------------------------------------------: | -----------: | ------------:| 81 | | borderRadius | Set if the card will have rounded edges | _Boolean_ | true 82 | | openInNewTab | Set if the link of article will openned in new tab | _Boolean_ | true 83 | | showTags | Define if the card will show article tags | _Boolean_ | false 84 | | showDate | Set if the card will show the date of the article | _Boolean_ | false 85 | | ssr | Set if the component should rendered on server | _Boolean_ | false| 86 | 87 | ### List 88 | 89 | -

Describe

90 | Shows a list with your Medium articles 91 | 92 | -

Screenshot

93 | Medium Posts Card List Preview 94 | 95 | -

Basic usage (with example)

96 | 97 | ```javascript 98 | import { List } from 'mediumpostscard' 99 | 100 | function Example(){ 101 | return ( 102 | 103 | ) 104 | } 105 | 106 | export default Example 107 | ``` 108 | 109 | -

Valid Props

110 | 111 | | Prop name | Description | Type | Default | 112 | | ---------- | :-----------------------------------------------: | -----------: | ------------:| 113 | | usernane | Sets your Medium username | _String_ | _underfined_ 114 | | dataMedium | Set data Medium (_only_ to Server Side Rendering) | _Object_ | _underfined_ 115 | | options | Object with options | _Object_ | _Object_| 116 | 117 | -

Valid Options

118 | 119 | | Option | Description | Type | Default | 120 | | -------------| :------------------------------------------------: | -----------: | ------------:| 121 | | openInNewTab | Set if the link of article will openned in new tab | _Boolean_ | true 122 | | showTags | Define if the card will show article tags | _Boolean_ | true 123 | | showDate | Set if the card will show the date of the article | _Boolean_ | true 124 | | borderRadius | Set if the card will have rounded edges | _Boolean_ | false 125 | | ssr | Set if the component should rendered on server | _Boolean_ | false| 126 | 127 | 128 | ### Label 129 | 130 | -

Describe

131 | Wrapper component that add label on other components 132 | 133 | -

Screenshot

134 | Medium Posts Card Carousel with label 135 | 136 | -

Example with carousel

137 | 138 | ```javascript 139 | import { Carousel, Label } from 'mediumpostscard' 140 | 141 | function Example(){ 142 | return ( 143 | 146 | ) 147 | } 148 | 149 | export default Example 150 | ``` 151 | 152 | -

Example with List

153 | 154 | ```javascript 155 | import { List, Label } from 'mediumpostscard' 156 | 157 | function Example(){ 158 | return ( 159 | 162 | ) 163 | } 164 | 165 | export default Example 166 | ``` 167 | -

Valid Props

168 | 169 | | Prop name | Description | Type | Default | 170 | | ---------- |:----------------------------------:| ----------: | ----------------:| 171 | | text | Set text on label | _String_ | 'Medium Articles' 172 | | children | Set component to be labeled | JSX.Element | No default 173 | 174 | ## Server Side Rendering 175 | 176 | -

Usage

177 | To make the component render the server do the prefetching: 178 | ```javascript 179 | const dataMedium = fetchMedium('yourmediumusername') 180 | ``` 181 | Next define _ssr_ as true, according to the example 182 | ```javascript 183 | 184 | ``` 185 | In the example above, I used the Carousel component, but you do the same with the List component. 186 | 187 | Next I will show an example of how to make server side on Next.js 188 | 189 | ```javascript 190 | import Head from 'next/head' 191 | import { List, fetchMedium } from 'mediumpostscard' 192 | 193 | export default function Home({dataMedium}) { 194 | return ( 195 |
196 | 197 | Create Next App 198 | 199 | 200 | 201 | 202 | 203 | 204 |
205 | ) 206 | } 207 | 208 | export async function getStaticProps() { 209 | const dataMedium = await fetchMedium('alex.streza') 210 | return { 211 | props: { 212 | dataMedium 213 | } 214 | } 215 | } 216 | 217 | ``` 218 | 219 | 220 | ## How to contribute 221 | 222 | Fork this repository, make clone for your machine. 223 | 224 | Install the dependencies with the command below: 225 | 226 | ```bash 227 | yarn install 228 | ``` 229 | 230 | To view on storybook 231 | 232 | ```bash 233 | yarn storybook 234 | ``` 235 | 236 | To build 237 | 238 | ```bash 239 | yarn build 240 | ``` 241 | To run the tests. 242 | 243 | ```bash 244 | yarn test 245 | ``` 246 | 247 | ## More 248 | 249 | Didn't you like any of the components? No problem! You can use Medium Posts API to build your own react component. 250 | Moreover you too can contribute with code. Feel free to add new features to our library. We are open-source. 251 | 252 | ## ✍️ Author 253 | 254 | - [@david-fernando](https://github.com/david-fernando) - Idea & Initial work -------------------------------------------------------------------------------- /dist/index.esm.js: -------------------------------------------------------------------------------- 1 | import { jsxs, jsx } from 'react/jsx-runtime'; 2 | import { useState, useEffect, useRef } from 'react'; 3 | import classnames from 'classnames'; 4 | import { GrFormPrevious, GrFormNext } from 'react-icons/gr'; 5 | 6 | /****************************************************************************** 7 | Copyright (c) Microsoft Corporation. 8 | 9 | Permission to use, copy, modify, and/or distribute this software for any 10 | purpose with or without fee is hereby granted. 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 13 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 14 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 15 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 16 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 17 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 18 | PERFORMANCE OF THIS SOFTWARE. 19 | ***************************************************************************** */ 20 | 21 | var __assign = function() { 22 | __assign = Object.assign || function __assign(t) { 23 | for (var s, i = 1, n = arguments.length; i < n; i++) { 24 | s = arguments[i]; 25 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; 26 | } 27 | return t; 28 | }; 29 | return __assign.apply(this, arguments); 30 | }; 31 | 32 | function __awaiter(thisArg, _arguments, P, generator) { 33 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 34 | return new (P || (P = Promise))(function (resolve, reject) { 35 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 36 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 37 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 38 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 39 | }); 40 | } 41 | 42 | function __generator(thisArg, body) { 43 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 44 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 45 | function verb(n) { return function (v) { return step([n, v]); }; } 46 | function step(op) { 47 | if (f) throw new TypeError("Generator is already executing."); 48 | while (_) try { 49 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 50 | if (y = 0, t) op = [op[0] & 2, t.value]; 51 | switch (op[0]) { 52 | case 0: case 1: t = op; break; 53 | case 4: _.label++; return { value: op[1], done: false }; 54 | case 5: _.label++; y = op[1]; op = [0]; continue; 55 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 56 | default: 57 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 58 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 59 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 60 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 61 | if (t[2]) _.ops.pop(); 62 | _.trys.pop(); continue; 63 | } 64 | op = body.call(thisArg, _); 65 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 66 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 67 | } 68 | } 69 | 70 | function useArray() { 71 | function array(array) { 72 | if (array === void 0) { array = []; } 73 | var isEmpty = (array.length === 0) ? true : false; 74 | return { 75 | isEmpty: isEmpty 76 | }; 77 | } 78 | return { 79 | array: array 80 | }; 81 | } 82 | 83 | function useBlankSpace(tagArray) { 84 | var tags = tagArray.map(function (item, index) { return item.concat(' '); }); 85 | return { 86 | tags: tags 87 | }; 88 | } 89 | 90 | var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n 0) { 159 | setPosition(position - displacement); 160 | } 161 | } 162 | return { 163 | position: position, 164 | moveForward: moveForward, 165 | moveBack: moveBack, 166 | }; 167 | } 168 | 169 | function useIsVisible(container, element) { 170 | var _a = useState(false), isVisible = _a[0], setIsVisible = _a[1]; 171 | var _b = useState(0), elementPosition = _b[0], setElementPosition = _b[1]; 172 | var _c = useState(0), containerWidth = _c[0], setContainerWidth = _c[1]; 173 | var elementDefaultValue = { x: 0 }; 174 | var containerDefaultValue = { width: 0 }; 175 | var timeInMiliseconds = 20; 176 | var excess = 110; 177 | setTimeout(function () { 178 | var _a, _b, _c, _d; 179 | var x = (((_b = (_a = element.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect) === null || _b === void 0 ? void 0 : _b.call(_a)) || elementDefaultValue).x; 180 | setElementPosition(x); 181 | var width = (((_d = (_c = container.current) === null || _c === void 0 ? void 0 : _c.getBoundingClientRect) === null || _d === void 0 ? void 0 : _d.call(_c)) || containerDefaultValue).width; 182 | setContainerWidth(width); 183 | }, timeInMiliseconds); 184 | useEffect(function () { 185 | determineIfElementIsVisible(); 186 | // eslint-disable-next-line 187 | }, [elementPosition]); 188 | function determineIfElementIsVisible() { 189 | var isElementVisible = (elementPosition + excess < containerWidth) ? true : false; 190 | setIsVisible(isElementVisible); 191 | } 192 | return isVisible; 193 | } 194 | 195 | function useLastCard() { 196 | function returnLastCard(cardItem, dataMedium, element) { 197 | var numberOfCards = dataMedium.length - 1; 198 | var lastCard = (cardItem === numberOfCards) ? element : null; 199 | return lastCard; 200 | } 201 | return { 202 | returnLastCard: returnLastCard 203 | }; 204 | } 205 | 206 | var css$3 = "html, body {\n font-size: 10px;\n}\n\na {\n text-decoration: none;\n}\n\n.Carousel_module_container__e69fb471 {\n width: 100%;\n height: 100%;\n min-height: 25rem;\n max-height: 40rem;\n display: block;\n background: none;\n overflow-x: hidden;\n padding-bottom: 0.2rem\n}\n\n.Carousel_module_content__e69fb471 {\n display: flex;\n position: relative;\n background: #fff;\n gap: 1rem;\n}\n\n.Carousel_module_carouselButton__e69fb471 {\n width: 4.0rem;\n height: 4.0rem;\n border-radius: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n position: relative;\n z-index: 1;\n border: 0;\n background: rgba(0,0,0,.5);\n opacity: 1;\n}\n\n.Carousel_module_previousButton__e69fb471 {\n margin-left: 0.5%;\n float: left;\n top: 11.4rem;\n}\n\n.Carousel_module_nextButton__e69fb471 {\n float: right;\n right: 1rem;\n top: -13.7rem;\n}\n\n.Carousel_module_iconButton__e69fb471 > polyline {\n stroke: #fff;\n}"; 207 | var modules_d1f32e6e = {"container":"Carousel_module_container__e69fb471","content":"Carousel_module_content__e69fb471","carouselButton":"Carousel_module_carouselButton__e69fb471","previousButton":"Carousel_module_previousButton__e69fb471","nextButton":"Carousel_module_nextButton__e69fb471","iconButton":"Carousel_module_iconButton__e69fb471"}; 208 | n(css$3,{}); 209 | 210 | function Carousel(_a) { 211 | var _b = _a.username, username = _b === void 0 ? '' : _b, dataMedium = _a.dataMedium, _c = _a.options, options = _c === void 0 ? {} : _c; 212 | var ssr = (options === null || options === void 0 ? void 0 : options.ssr) || false; 213 | var data = useGetMedium(username, ssr); 214 | var medium = (ssr) ? dataMedium === null || dataMedium === void 0 ? void 0 : dataMedium.dataMedium : data; 215 | var _d = useCarousel(), moveForward = _d.moveForward, moveBack = _d.moveBack, position = _d.position; 216 | var openInNewTab = (options.hasOwnProperty('openInNewTab')) ? options.openInNewTab : true; 217 | var nameTarget = (openInNewTab) ? '_blank' : '_self'; 218 | var cardContainer = useRef(); 219 | var carouselContainer = useRef(); 220 | var cardIsVisible = useIsVisible(carouselContainer, cardContainer); 221 | var returnLastCard = useLastCard().returnLastCard; 222 | return (jsxs("div", __assign({ className: modules_d1f32e6e.container, ref: carouselContainer }, { children: [(position > 0) && (jsx("button", __assign({ onClick: function () { return moveBack(); }, className: classnames(modules_d1f32e6e.carouselButton, modules_d1f32e6e.previousButton) }, { children: jsx(GrFormPrevious, { className: modules_d1f32e6e.iconButton, size: 24 }) }))), jsx("span", __assign({ className: modules_d1f32e6e.content, style: { right: "".concat(position, "rem"), transition: 'right 0.6s linear' } }, { children: medium.map(function (item, index) { return (jsx("a", __assign({ href: item.link, ref: returnLastCard(index, medium, cardContainer), target: nameTarget }, { children: jsx(Card, { userdata: item, options: options }) }), index)); }) })), (!cardIsVisible) && (jsx("button", __assign({ onClick: function () { return moveForward(cardIsVisible); }, className: classnames(modules_d1f32e6e.carouselButton, modules_d1f32e6e.nextButton) }, { children: jsx(GrFormNext, { className: modules_d1f32e6e.iconButton, size: 24 }) })))] }))); 223 | } 224 | 225 | var css$2 = ".RectangularCard_module_container__e8f8839b {\n width: 100%;\n height: max-content;\n min-height: 19rem;\n display: flex;\n background: #fff;\n border: 1px solid rgba(0,0,0,.2);\n font-size: 10px;\n font-family: 'Roboto', sans-serif;\n margin: 0;\n gap: 1rem;\n}\n\n.RectangularCard_module_borderRadiusContainer__e8f8839b {\n border-radius: 10px;\n}\n\n.RectangularCard_module_thumbnail__e8f8839b {\n width: 19rem;\n height: 100%;\n min-height: 5rem;\n min-width: 5rem;\n aspect-ratio: 1/1;\n}\n\n.RectangularCard_module_borderRadiusThumbnail__e8f8839b {\n border-top-left-radius: 10px;\n border-bottom-left-radius: 10px\n}\n\n.RectangularCard_module_content__e8f8839b {\n padding: 10px;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n gap: 0.8rem;\n height: max-content;\n max-height: 40rem;\n}\n\n.RectangularCard_module_details__e8f8839b {\n display: flex;\n flex-direction: column;\n flex-wrap: wrap;\n gap: 0rem;\n}\n\n.RectangularCard_module_title__e8f8839b, .RectangularCard_module_description__e8f8839b, .RectangularCard_module_date__e8f8839b, .RectangularCard_module_tags__e8f8839b {\n font-size: 1.6rem;\n color: #53565b\n}\n\n.RectangularCard_module_title__e8f8839b {\n font-size: 2.6rem;\n font-weight: 700;\n text-overflow: ellipsis;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: 2;\n display: -webkit-box;\n}\n\n.RectangularCard_module_description__e8f8839b {\n font-size: 1.6rem;\n text-align: initial;\n max-height: 44%;\n text-overflow: ellipsis;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: 2;\n display: -webkit-box;\n overflow: hidden;\n}\n\n.RectangularCard_module_date__e8f8839b, .RectangularCard_module_tags__e8f8839b {\n font-size: 1.2rem;\n}\n\n.RectangularCard_module_tags__e8f8839b {\n word-spacing: 0.5rem;\n line-height: 1.3rem;\n}\n\n@media (max-width: 890px) {\n .RectangularCard_module_title__e8f8839b {\n font-size: 1.6rem;\n }\n .RectangularCard_module_description__e8f8839b {\n font-size: 1.5rem;\n }\n .RectangularCard_module_thumbnail__e8f8839b {\n width: 18rem;\n height: 100%;\n }\n .RectangularCard_module_content__e8f8839b {\n gap: 0.5rem;\n height: 14rem;\n }\n}\n\n@media (max-width: 526px) {\n .RectangularCard_module_description__e8f8839b {\n overflow: visible;\n }\n .RectangularCard_module_thumbnail__e8f8839b {\n width: 100%;\n height: 24rem;\n }\n .RectangularCard_module_container__e8f8839b {\n flex-direction: column;\n height: 100%;\n min-height: 43rem;\n }\n .RectangularCard_module_content__e8f8839b {\n gap: 0rem;\n }\n}\n"; 226 | var modules_cb0e83ce = {"container":"RectangularCard_module_container__e8f8839b","borderRadiusContainer":"RectangularCard_module_borderRadiusContainer__e8f8839b","thumbnail":"RectangularCard_module_thumbnail__e8f8839b","borderRadiusThumbnail":"RectangularCard_module_borderRadiusThumbnail__e8f8839b","content":"RectangularCard_module_content__e8f8839b","details":"RectangularCard_module_details__e8f8839b","title":"RectangularCard_module_title__e8f8839b","description":"RectangularCard_module_description__e8f8839b","date":"RectangularCard_module_date__e8f8839b","tags":"RectangularCard_module_tags__e8f8839b"}; 227 | n(css$2,{}); 228 | 229 | function RectangularCard(_a) { 230 | var userdata = _a.userdata, _b = _a.options, options = _b === void 0 ? {} : _b; 231 | var array = useArray().array; 232 | var borderRadius = (options.hasOwnProperty('borderRadius')) ? options.borderRadius : false; 233 | var showDate = (options.hasOwnProperty('showDate')) ? options.showDate : true; 234 | var showTags = (options.hasOwnProperty('showTags')) ? options.showTags : true; 235 | var borderRadiusContainer = (borderRadius) && modules_cb0e83ce.borderRadiusContainer; 236 | var borderRadiusThumbnail = (borderRadius) && modules_cb0e83ce.borderRadiusThumbnail; 237 | var tagArray = (array(userdata.tags).isEmpty) ? ['NoTags'] : userdata.tags; 238 | var tags = useBlankSpace(tagArray).tags; 239 | return (jsxs("div", __assign({ className: classnames(modules_cb0e83ce.container, borderRadiusContainer) }, { children: [jsx("span", { children: jsx("img", { className: classnames(modules_cb0e83ce.thumbnail, borderRadiusThumbnail), src: userdata.image, alt: userdata.title }) }), jsxs("span", __assign({ className: modules_cb0e83ce.content }, { children: [jsx("span", __assign({ className: modules_cb0e83ce.title }, { children: userdata.title })), jsx("p", __assign({ className: modules_cb0e83ce.description }, { children: userdata.description })), jsxs("span", __assign({ className: modules_cb0e83ce.details }, { children: [(showDate) && (jsx("p", __assign({ className: modules_cb0e83ce.date }, { children: userdata.date }))), (showTags) && (jsx("p", __assign({ className: modules_cb0e83ce.tags }, { children: tags })))] }))] }))] }))); 240 | } 241 | 242 | var css$1 = "html, body {\n font-size: 10px;\n}\n\na {\n text-decoration: none;\n}\n\n.List_module_container__d9646218 {\n width: 100%;\n height: 100%;\n display: block;\n background: none;\n padding-bottom: 0.2rem\n}\n\n.List_module_content__d9646218 {\n display: flex;\n flex-direction: column;\n position: relative;\n background: #fff;\n gap: 1rem;\n}"; 243 | var modules_7b101142 = {"container":"List_module_container__d9646218","content":"List_module_content__d9646218"}; 244 | n(css$1,{}); 245 | 246 | function List(_a) { 247 | var _b = _a.username, username = _b === void 0 ? '' : _b, dataMedium = _a.dataMedium, _c = _a.options, options = _c === void 0 ? {} : _c; 248 | var ssr = (options === null || options === void 0 ? void 0 : options.ssr) || false; 249 | var data = useGetMedium(username, ssr); 250 | var medium = (ssr) ? dataMedium === null || dataMedium === void 0 ? void 0 : dataMedium.dataMedium : data; 251 | var openInNewTab = (options.hasOwnProperty('openInNewTab')) ? options.openInNewTab : true; 252 | var nameTarget = (openInNewTab) ? '_blank' : '_self'; 253 | return (jsx("div", __assign({ className: modules_7b101142.container }, { children: jsx("span", __assign({ className: modules_7b101142.content }, { children: medium.map(function (item, index) { return (jsx("a", __assign({ href: item.link, target: nameTarget }, { children: jsx(RectangularCard, { userdata: item, options: options }) }), index)); }) })) }))); 254 | } 255 | 256 | var css = ".Label_module_container__ee32c7c2 {\n align-items: flex-start;\n display: flex;\n flex-direction: column;\n gap: 1rem;\n height: 0px auto;\n max-width: 100%;\n }\n\n .Label_module_title__ee32c7c2 {\n font-size: 2.4rem;\n color: #53565b;\n font-family: Roboto, sans-serif;\n }\n \n @media (max-width: 717px) {\n .Label_module_container__ee32c7c2 {\n align-items: center;\n }\n }"; 257 | var modules_536e8d56 = {"container":"Label_module_container__ee32c7c2","title":"Label_module_title__ee32c7c2"}; 258 | n(css,{}); 259 | 260 | function Label(_a) { 261 | var _b = _a.text, text = _b === void 0 ? 'Medium Articles' : _b, children = _a.children; 262 | return (jsxs("div", __assign({ className: modules_536e8d56.container }, { children: [jsx("span", __assign({ className: modules_536e8d56.title }, { children: text })), children] }))); 263 | } 264 | 265 | export { Carousel, Label, List, fetchMedium }; 266 | -------------------------------------------------------------------------------- /dist/index.cjs.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | var jsxRuntime = require('react/jsx-runtime'); 6 | var react = require('react'); 7 | var classnames = require('classnames'); 8 | var gr = require('react-icons/gr'); 9 | 10 | function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } 11 | 12 | var classnames__default = /*#__PURE__*/_interopDefaultLegacy(classnames); 13 | 14 | /****************************************************************************** 15 | Copyright (c) Microsoft Corporation. 16 | 17 | Permission to use, copy, modify, and/or distribute this software for any 18 | purpose with or without fee is hereby granted. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 21 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 22 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 23 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 24 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 25 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 26 | PERFORMANCE OF THIS SOFTWARE. 27 | ***************************************************************************** */ 28 | 29 | var __assign = function() { 30 | __assign = Object.assign || function __assign(t) { 31 | for (var s, i = 1, n = arguments.length; i < n; i++) { 32 | s = arguments[i]; 33 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; 34 | } 35 | return t; 36 | }; 37 | return __assign.apply(this, arguments); 38 | }; 39 | 40 | function __awaiter(thisArg, _arguments, P, generator) { 41 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 42 | return new (P || (P = Promise))(function (resolve, reject) { 43 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 44 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 45 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 46 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 47 | }); 48 | } 49 | 50 | function __generator(thisArg, body) { 51 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 52 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 53 | function verb(n) { return function (v) { return step([n, v]); }; } 54 | function step(op) { 55 | if (f) throw new TypeError("Generator is already executing."); 56 | while (_) try { 57 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 58 | if (y = 0, t) op = [op[0] & 2, t.value]; 59 | switch (op[0]) { 60 | case 0: case 1: t = op; break; 61 | case 4: _.label++; return { value: op[1], done: false }; 62 | case 5: _.label++; y = op[1]; op = [0]; continue; 63 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 64 | default: 65 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 66 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 67 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 68 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 69 | if (t[2]) _.ops.pop(); 70 | _.trys.pop(); continue; 71 | } 72 | op = body.call(thisArg, _); 73 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 74 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 75 | } 76 | } 77 | 78 | function useArray() { 79 | function array(array) { 80 | if (array === void 0) { array = []; } 81 | var isEmpty = (array.length === 0) ? true : false; 82 | return { 83 | isEmpty: isEmpty 84 | }; 85 | } 86 | return { 87 | array: array 88 | }; 89 | } 90 | 91 | function useBlankSpace(tagArray) { 92 | var tags = tagArray.map(function (item, index) { return item.concat(' '); }); 93 | return { 94 | tags: tags 95 | }; 96 | } 97 | 98 | var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n 0) { 167 | setPosition(position - displacement); 168 | } 169 | } 170 | return { 171 | position: position, 172 | moveForward: moveForward, 173 | moveBack: moveBack, 174 | }; 175 | } 176 | 177 | function useIsVisible(container, element) { 178 | var _a = react.useState(false), isVisible = _a[0], setIsVisible = _a[1]; 179 | var _b = react.useState(0), elementPosition = _b[0], setElementPosition = _b[1]; 180 | var _c = react.useState(0), containerWidth = _c[0], setContainerWidth = _c[1]; 181 | var elementDefaultValue = { x: 0 }; 182 | var containerDefaultValue = { width: 0 }; 183 | var timeInMiliseconds = 20; 184 | var excess = 110; 185 | setTimeout(function () { 186 | var _a, _b, _c, _d; 187 | var x = (((_b = (_a = element.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect) === null || _b === void 0 ? void 0 : _b.call(_a)) || elementDefaultValue).x; 188 | setElementPosition(x); 189 | var width = (((_d = (_c = container.current) === null || _c === void 0 ? void 0 : _c.getBoundingClientRect) === null || _d === void 0 ? void 0 : _d.call(_c)) || containerDefaultValue).width; 190 | setContainerWidth(width); 191 | }, timeInMiliseconds); 192 | react.useEffect(function () { 193 | determineIfElementIsVisible(); 194 | // eslint-disable-next-line 195 | }, [elementPosition]); 196 | function determineIfElementIsVisible() { 197 | var isElementVisible = (elementPosition + excess < containerWidth) ? true : false; 198 | setIsVisible(isElementVisible); 199 | } 200 | return isVisible; 201 | } 202 | 203 | function useLastCard() { 204 | function returnLastCard(cardItem, dataMedium, element) { 205 | var numberOfCards = dataMedium.length - 1; 206 | var lastCard = (cardItem === numberOfCards) ? element : null; 207 | return lastCard; 208 | } 209 | return { 210 | returnLastCard: returnLastCard 211 | }; 212 | } 213 | 214 | var css$3 = "html, body {\n font-size: 10px;\n}\n\na {\n text-decoration: none;\n}\n\n.Carousel_module_container__e69fb471 {\n width: 100%;\n height: 100%;\n min-height: 25rem;\n max-height: 40rem;\n display: block;\n background: none;\n overflow-x: hidden;\n padding-bottom: 0.2rem\n}\n\n.Carousel_module_content__e69fb471 {\n display: flex;\n position: relative;\n background: #fff;\n gap: 1rem;\n}\n\n.Carousel_module_carouselButton__e69fb471 {\n width: 4.0rem;\n height: 4.0rem;\n border-radius: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n position: relative;\n z-index: 1;\n border: 0;\n background: rgba(0,0,0,.5);\n opacity: 1;\n}\n\n.Carousel_module_previousButton__e69fb471 {\n margin-left: 0.5%;\n float: left;\n top: 11.4rem;\n}\n\n.Carousel_module_nextButton__e69fb471 {\n float: right;\n right: 1rem;\n top: -13.7rem;\n}\n\n.Carousel_module_iconButton__e69fb471 > polyline {\n stroke: #fff;\n}"; 215 | var modules_d1f32e6e = {"container":"Carousel_module_container__e69fb471","content":"Carousel_module_content__e69fb471","carouselButton":"Carousel_module_carouselButton__e69fb471","previousButton":"Carousel_module_previousButton__e69fb471","nextButton":"Carousel_module_nextButton__e69fb471","iconButton":"Carousel_module_iconButton__e69fb471"}; 216 | n(css$3,{}); 217 | 218 | function Carousel(_a) { 219 | var _b = _a.username, username = _b === void 0 ? '' : _b, dataMedium = _a.dataMedium, _c = _a.options, options = _c === void 0 ? {} : _c; 220 | var ssr = (options === null || options === void 0 ? void 0 : options.ssr) || false; 221 | var data = useGetMedium(username, ssr); 222 | var medium = (ssr) ? dataMedium === null || dataMedium === void 0 ? void 0 : dataMedium.dataMedium : data; 223 | var _d = useCarousel(), moveForward = _d.moveForward, moveBack = _d.moveBack, position = _d.position; 224 | var openInNewTab = (options.hasOwnProperty('openInNewTab')) ? options.openInNewTab : true; 225 | var nameTarget = (openInNewTab) ? '_blank' : '_self'; 226 | var cardContainer = react.useRef(); 227 | var carouselContainer = react.useRef(); 228 | var cardIsVisible = useIsVisible(carouselContainer, cardContainer); 229 | var returnLastCard = useLastCard().returnLastCard; 230 | return (jsxRuntime.jsxs("div", __assign({ className: modules_d1f32e6e.container, ref: carouselContainer }, { children: [(position > 0) && (jsxRuntime.jsx("button", __assign({ onClick: function () { return moveBack(); }, className: classnames__default["default"](modules_d1f32e6e.carouselButton, modules_d1f32e6e.previousButton) }, { children: jsxRuntime.jsx(gr.GrFormPrevious, { className: modules_d1f32e6e.iconButton, size: 24 }) }))), jsxRuntime.jsx("span", __assign({ className: modules_d1f32e6e.content, style: { right: "".concat(position, "rem"), transition: 'right 0.6s linear' } }, { children: medium.map(function (item, index) { return (jsxRuntime.jsx("a", __assign({ href: item.link, ref: returnLastCard(index, medium, cardContainer), target: nameTarget }, { children: jsxRuntime.jsx(Card, { userdata: item, options: options }) }), index)); }) })), (!cardIsVisible) && (jsxRuntime.jsx("button", __assign({ onClick: function () { return moveForward(cardIsVisible); }, className: classnames__default["default"](modules_d1f32e6e.carouselButton, modules_d1f32e6e.nextButton) }, { children: jsxRuntime.jsx(gr.GrFormNext, { className: modules_d1f32e6e.iconButton, size: 24 }) })))] }))); 231 | } 232 | 233 | var css$2 = ".RectangularCard_module_container__e8f8839b {\n width: 100%;\n height: max-content;\n min-height: 19rem;\n display: flex;\n background: #fff;\n border: 1px solid rgba(0,0,0,.2);\n font-size: 10px;\n font-family: 'Roboto', sans-serif;\n margin: 0;\n gap: 1rem;\n}\n\n.RectangularCard_module_borderRadiusContainer__e8f8839b {\n border-radius: 10px;\n}\n\n.RectangularCard_module_thumbnail__e8f8839b {\n width: 19rem;\n height: 100%;\n min-height: 5rem;\n min-width: 5rem;\n aspect-ratio: 1/1;\n}\n\n.RectangularCard_module_borderRadiusThumbnail__e8f8839b {\n border-top-left-radius: 10px;\n border-bottom-left-radius: 10px\n}\n\n.RectangularCard_module_content__e8f8839b {\n padding: 10px;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n gap: 0.8rem;\n height: max-content;\n max-height: 40rem;\n}\n\n.RectangularCard_module_details__e8f8839b {\n display: flex;\n flex-direction: column;\n flex-wrap: wrap;\n gap: 0rem;\n}\n\n.RectangularCard_module_title__e8f8839b, .RectangularCard_module_description__e8f8839b, .RectangularCard_module_date__e8f8839b, .RectangularCard_module_tags__e8f8839b {\n font-size: 1.6rem;\n color: #53565b\n}\n\n.RectangularCard_module_title__e8f8839b {\n font-size: 2.6rem;\n font-weight: 700;\n text-overflow: ellipsis;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: 2;\n display: -webkit-box;\n}\n\n.RectangularCard_module_description__e8f8839b {\n font-size: 1.6rem;\n text-align: initial;\n max-height: 44%;\n text-overflow: ellipsis;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: 2;\n display: -webkit-box;\n overflow: hidden;\n}\n\n.RectangularCard_module_date__e8f8839b, .RectangularCard_module_tags__e8f8839b {\n font-size: 1.2rem;\n}\n\n.RectangularCard_module_tags__e8f8839b {\n word-spacing: 0.5rem;\n line-height: 1.3rem;\n}\n\n@media (max-width: 890px) {\n .RectangularCard_module_title__e8f8839b {\n font-size: 1.6rem;\n }\n .RectangularCard_module_description__e8f8839b {\n font-size: 1.5rem;\n }\n .RectangularCard_module_thumbnail__e8f8839b {\n width: 18rem;\n height: 100%;\n }\n .RectangularCard_module_content__e8f8839b {\n gap: 0.5rem;\n height: 14rem;\n }\n}\n\n@media (max-width: 526px) {\n .RectangularCard_module_description__e8f8839b {\n overflow: visible;\n }\n .RectangularCard_module_thumbnail__e8f8839b {\n width: 100%;\n height: 24rem;\n }\n .RectangularCard_module_container__e8f8839b {\n flex-direction: column;\n height: 100%;\n min-height: 43rem;\n }\n .RectangularCard_module_content__e8f8839b {\n gap: 0rem;\n }\n}\n"; 234 | var modules_cb0e83ce = {"container":"RectangularCard_module_container__e8f8839b","borderRadiusContainer":"RectangularCard_module_borderRadiusContainer__e8f8839b","thumbnail":"RectangularCard_module_thumbnail__e8f8839b","borderRadiusThumbnail":"RectangularCard_module_borderRadiusThumbnail__e8f8839b","content":"RectangularCard_module_content__e8f8839b","details":"RectangularCard_module_details__e8f8839b","title":"RectangularCard_module_title__e8f8839b","description":"RectangularCard_module_description__e8f8839b","date":"RectangularCard_module_date__e8f8839b","tags":"RectangularCard_module_tags__e8f8839b"}; 235 | n(css$2,{}); 236 | 237 | function RectangularCard(_a) { 238 | var userdata = _a.userdata, _b = _a.options, options = _b === void 0 ? {} : _b; 239 | var array = useArray().array; 240 | var borderRadius = (options.hasOwnProperty('borderRadius')) ? options.borderRadius : false; 241 | var showDate = (options.hasOwnProperty('showDate')) ? options.showDate : true; 242 | var showTags = (options.hasOwnProperty('showTags')) ? options.showTags : true; 243 | var borderRadiusContainer = (borderRadius) && modules_cb0e83ce.borderRadiusContainer; 244 | var borderRadiusThumbnail = (borderRadius) && modules_cb0e83ce.borderRadiusThumbnail; 245 | var tagArray = (array(userdata.tags).isEmpty) ? ['NoTags'] : userdata.tags; 246 | var tags = useBlankSpace(tagArray).tags; 247 | return (jsxRuntime.jsxs("div", __assign({ className: classnames__default["default"](modules_cb0e83ce.container, borderRadiusContainer) }, { children: [jsxRuntime.jsx("span", { children: jsxRuntime.jsx("img", { className: classnames__default["default"](modules_cb0e83ce.thumbnail, borderRadiusThumbnail), src: userdata.image, alt: userdata.title }) }), jsxRuntime.jsxs("span", __assign({ className: modules_cb0e83ce.content }, { children: [jsxRuntime.jsx("span", __assign({ className: modules_cb0e83ce.title }, { children: userdata.title })), jsxRuntime.jsx("p", __assign({ className: modules_cb0e83ce.description }, { children: userdata.description })), jsxRuntime.jsxs("span", __assign({ className: modules_cb0e83ce.details }, { children: [(showDate) && (jsxRuntime.jsx("p", __assign({ className: modules_cb0e83ce.date }, { children: userdata.date }))), (showTags) && (jsxRuntime.jsx("p", __assign({ className: modules_cb0e83ce.tags }, { children: tags })))] }))] }))] }))); 248 | } 249 | 250 | var css$1 = "html, body {\n font-size: 10px;\n}\n\na {\n text-decoration: none;\n}\n\n.List_module_container__d9646218 {\n width: 100%;\n height: 100%;\n display: block;\n background: none;\n padding-bottom: 0.2rem\n}\n\n.List_module_content__d9646218 {\n display: flex;\n flex-direction: column;\n position: relative;\n background: #fff;\n gap: 1rem;\n}"; 251 | var modules_7b101142 = {"container":"List_module_container__d9646218","content":"List_module_content__d9646218"}; 252 | n(css$1,{}); 253 | 254 | function List(_a) { 255 | var _b = _a.username, username = _b === void 0 ? '' : _b, dataMedium = _a.dataMedium, _c = _a.options, options = _c === void 0 ? {} : _c; 256 | var ssr = (options === null || options === void 0 ? void 0 : options.ssr) || false; 257 | var data = useGetMedium(username, ssr); 258 | var medium = (ssr) ? dataMedium === null || dataMedium === void 0 ? void 0 : dataMedium.dataMedium : data; 259 | var openInNewTab = (options.hasOwnProperty('openInNewTab')) ? options.openInNewTab : true; 260 | var nameTarget = (openInNewTab) ? '_blank' : '_self'; 261 | return (jsxRuntime.jsx("div", __assign({ className: modules_7b101142.container }, { children: jsxRuntime.jsx("span", __assign({ className: modules_7b101142.content }, { children: medium.map(function (item, index) { return (jsxRuntime.jsx("a", __assign({ href: item.link, target: nameTarget }, { children: jsxRuntime.jsx(RectangularCard, { userdata: item, options: options }) }), index)); }) })) }))); 262 | } 263 | 264 | var css = ".Label_module_container__ee32c7c2 {\n align-items: flex-start;\n display: flex;\n flex-direction: column;\n gap: 1rem;\n height: 0px auto;\n max-width: 100%;\n }\n\n .Label_module_title__ee32c7c2 {\n font-size: 2.4rem;\n color: #53565b;\n font-family: Roboto, sans-serif;\n }\n \n @media (max-width: 717px) {\n .Label_module_container__ee32c7c2 {\n align-items: center;\n }\n }"; 265 | var modules_536e8d56 = {"container":"Label_module_container__ee32c7c2","title":"Label_module_title__ee32c7c2"}; 266 | n(css,{}); 267 | 268 | function Label(_a) { 269 | var _b = _a.text, text = _b === void 0 ? 'Medium Articles' : _b, children = _a.children; 270 | return (jsxRuntime.jsxs("div", __assign({ className: modules_536e8d56.container }, { children: [jsxRuntime.jsx("span", __assign({ className: modules_536e8d56.title }, { children: text })), children] }))); 271 | } 272 | 273 | exports.Carousel = Carousel; 274 | exports.Label = Label; 275 | exports.List = List; 276 | exports.fetchMedium = fetchMedium; 277 | --------------------------------------------------------------------------------