Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Html block.
Browse files Browse the repository at this point in the history
  • Loading branch information
pelusanchez committed Oct 20, 2023
1 parent dc23519 commit 9fa39b6
Show file tree
Hide file tree
Showing 10 changed files with 17,019 additions and 1,717 deletions.
33 changes: 33 additions & 0 deletions __tests__/components/blocks/HtmlBlock.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react'
import { render, screen } from '@testing-library/react'

import { HtmlBlock } from '../../../src/components'

describe('type html', () => {
it('it renders correctly', () => {
render(
<HtmlBlock
block={{
type: 'html',
id: 'test-id-1',
content:
'<div>This is a raw HTML</div><p>With more HTML</p>',
}}
/>,
)

screen.getByText('This is a raw HTML')
screen.getByText('With more HTML')
})
it('it renders correctly without content', () => {
render(
<HtmlBlock
block={{
type: 'html',
id: 'test-id-1',
content: null as unknown as string,
}}
/>,
)
})
})
8,699 changes: 6,989 additions & 1,710 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"build": "tsc",
"lint": "eslint 'src/**/*.{js,jsx,ts,tsx}'",
"lint:fix": "eslint --fix 'src/**/*.{jsx,ts,tsx}'",
"format": "prettier --write src//**/*.{ts,tsx,css} --config ./.prettierrc",
"format": "prettier --write src/**/*.{ts,tsx} --config ./.prettierrc",
"preview": "vite preview",
"prepare": "husky install",
"lint-staged": "npm run lint && npm run format",
Expand All @@ -36,6 +36,7 @@
"devDependencies": {
"@babel/preset-env": "^7.22.9",
"@babel/preset-react": "^7.22.5",
"@ladle/react": "^3.2.2",
"@rollup/plugin-typescript": "^11.1.2",
"@testing-library/dom": "^9.3.1",
"@testing-library/jest-dom": "^5.17.0",
Expand Down Expand Up @@ -65,7 +66,7 @@
"ts-jest": "^29.1.1",
"typescript": "^5.0.2",
"vite": "^4.4.0",
"vite-plugin-dts": "^1.0.5",
"vite-plugin-dts": "^1.7.3",
"vite-plugin-linter": "^2.0.2"
},
"peerDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions src/components/GenerateBlocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ import {
ButtonBlockInterface,
LayoutSectionBlocksMix,
MarkdownBlockInterface,
HtmlBlockInteface,
} from '../models'
import { HtmlBlock } from './blocks/HtmlBlock'

const generateBlockByType = {
['markdown']: (block: MarkdownBlockInterface, markdownParsingOptions: MarkdownToJSX.Options) => (
<MarkdownBlock block={block} markdownParsingOptions={markdownParsingOptions} />
),
['html']: (block: HtmlBlockInteface) => <HtmlBlock block={block} />,
['table']: (block: TableBlock) => <Table block={block} />,
['thumb-markdown']: (
block: ThumbMarkdownBlock,
Expand Down
17 changes: 17 additions & 0 deletions src/components/blocks/HtmlBlock.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import { HtmlBlock } from './HtmlBlock';

export const HtmlBlockStory = () => (<div style={
{
width: '100%',
height: '100%',
}
}>
<HtmlBlock
block={{
'id': 'html',
'type': 'html',
'content': `<div>This is an HTML</div> <b>inside</b> <p>an HTML block</p>`
}}
/>
</div>);
29 changes: 29 additions & 0 deletions src/components/blocks/HtmlBlock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react'

import styled from 'styled-components'

import { HtmlBlockInteface, } from '../../models'

export const HtmlBlock = ({
block,
}: {
block: HtmlBlockInteface
}) => (
<Content data-stylizable="block html-content">
{block?.content && (
<ContentWrapper dangerouslySetInnerHTML={{ __html: block.content }} />
)}
</Content>
)

const Content = styled.div`
display: flex;
margin: 0;
flex-direction: column;
justify-content: flex-start;
`

const ContentWrapper = styled.div`
width: 100%;
height: 100%;
`
1 change: 1 addition & 0 deletions src/components/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export * from './LinkBlock'
export * from './Markdown'
export * from './Section'
export * from './Table'
export * from './HtmlBlock'
export * from './ThumbMarkdown'
9 changes: 8 additions & 1 deletion src/models/datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export enum LayoutBlockTypes {
'button',
'link',
'markdown',
'html',
'section',
'table',
'thumb-markdown',
Expand All @@ -17,6 +18,10 @@ export interface MarkdownBlockInterface extends GenericBlock {
content: string
}

export interface HtmlBlockInteface extends GenericBlock {
content: string
}

export type TableBlockHeadings = {
id: string
label: string
Expand All @@ -38,7 +43,7 @@ export interface TableBlock extends GenericBlock {
export interface SectionBlock extends GenericBlock {
title: string
open: boolean
blocks: (MarkdownBlockInterface | LinkBlockInterface | ButtonBlockInterface)[]
blocks: (HtmlBlockInteface | MarkdownBlockInterface | LinkBlockInterface | ButtonBlockInterface)[]
}

export type ImageThumb = {
Expand Down Expand Up @@ -79,6 +84,7 @@ export interface ButtonBlockInterface extends GenericBlock {

export type LayoutSectionBlock =
| MarkdownBlockInterface
| HtmlBlockInteface
| TableBlock
| ThumbMarkdownBlock
| LinkBlockInterface
Expand All @@ -88,6 +94,7 @@ export type LayoutSectionBlock =

export type LayoutSectionBlocksMix = MarkdownBlockInterface &
TableBlock &
HtmlBlockInteface &
ThumbMarkdownBlock &
LinkBlockInterface &
SectionBlock &
Expand Down
5 changes: 1 addition & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import { resolve } from 'node:path'
import { defineConfig } from 'vite'

import react from '@vitejs/plugin-react'
import dts from 'vite-plugin-dts'
import EsLint from 'vite-plugin-linter'
import { EsLinter, linterPlugin, } from "vite-plugin-linter";
import typescript from '@rollup/plugin-typescript'

import * as packageJson from './package.json'

const { EsLinter, linterPlugin } = EsLint

// https://vitejs.dev/config/
export default defineConfig((configEnv) => ({
plugins: [
Expand Down
Loading

0 comments on commit 9fa39b6

Please sign in to comment.