Skip to content

Commit 06f4e38

Browse files
committed
feat(markdown): implement component
1 parent 74bd1f0 commit 06f4e38

File tree

34 files changed

+1031
-19
lines changed

34 files changed

+1031
-19
lines changed

packages/ods-react/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@
4040
"classnames": "2.5.1",
4141
"libphonenumber-js": "1.12.8",
4242
"react-hot-toast": "2.6.0",
43+
"react-markdown": "10.1.0",
4344
"react-shiki": "0.9.0",
44-
"react-swipeable": "7.0.2"
45+
"react-swipeable": "7.0.2",
46+
"remark-gfm": "4.0.1"
4547
},
4648
"peerDependencies": {
4749
"react": ">=18.2.0",

packages/ods-react/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ export * from './menu/src';
5050
export * from './cart/src';
5151
export * from './file-thumbnail/src';
5252
export * from './data-table/src';
53+
export * from './markdown/src';
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { StorybookConfig } from '@storybook/react-vite';
2+
3+
const config: StorybookConfig = {
4+
core: {
5+
disableTelemetry: true,
6+
disableWhatsNewNotifications: true,
7+
},
8+
docs: {
9+
autodocs: false,
10+
},
11+
framework: '@storybook/react-vite',
12+
previewHead: (head) => `
13+
${head}
14+
<style>
15+
html, body {
16+
font-family: "Source Sans Pro", "Trebuchet MS", "Arial", "Segoe UI", sans-serif;
17+
}
18+
</style>
19+
`,
20+
stories: [
21+
'../src/dev.stories.tsx',
22+
'../tests/**/*.stories.tsx',
23+
],
24+
};
25+
26+
export default config;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { addons } from '@storybook/manager-api';
2+
3+
addons.register('custom-panel', (api) => {
4+
api.togglePanel(false);
5+
});
6+
7+
addons.setConfig({
8+
enableShortcuts: false,
9+
showToolbar: true,
10+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { type Preview } from '@storybook/react';
2+
import '@ovhcloud/ods-themes/default/css';
3+
import '@ovhcloud/ods-themes/default/fonts';
4+
5+
const preview: Preview = {
6+
parameters: {},
7+
};
8+
9+
export default preview;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const isCI = !!process.env.CI;
2+
3+
export default {
4+
launch: {
5+
headless: isCI,
6+
slowMo: isCI ? 0 : 300,
7+
product: 'chrome',
8+
args: [
9+
'--no-sandbox',
10+
'--disable-setuid-sandbox',
11+
"--disable-dev-shm-usage",
12+
"--disable-accelerated-2d-canvas",
13+
"--disable-gpu",
14+
'--font-render-hinting=none',
15+
],
16+
},
17+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const baseOption = {
2+
collectCoverage: false,
3+
testPathIgnorePatterns: [
4+
'node_modules/',
5+
'dist/',
6+
],
7+
testRegex: 'tests\\/.*\\.spec\\.(ts|tsx)$',
8+
transform: {
9+
'\\.(ts|tsx)$': 'ts-jest',
10+
},
11+
verbose: true,
12+
};
13+
14+
export default !!process.env.E2E ?
15+
{
16+
...baseOption,
17+
preset: 'jest-puppeteer',
18+
testRegex: 'tests\\/.*\\.e2e\\.ts$',
19+
testTimeout: 60000,
20+
} : {
21+
...baseOption,
22+
transform: {
23+
...baseOption.transform,
24+
'\\.scss$': 'jest-transform-stub',
25+
}
26+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare module '*.css';
2+
declare module '*.scss';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "@ovhcloud/ods-react-markdown",
3+
"version": "19.6.1",
4+
"private": true,
5+
"description": "ODS React Markdown component",
6+
"type": "module",
7+
"main": "dist/index.js",
8+
"scripts": {
9+
"clean": "rimraf documentation node_modules",
10+
"doc": "npm run clean && npm run doc:ts && npm run doc:css",
11+
"doc:css": "sass src/components:documentation --no-source-map --pkg-importer=node && node ../../../scripts/generate-component-token-list.js",
12+
"doc:ts": "typedoc",
13+
"lint:scss": "stylelint --aei 'src/components/**/*.scss'",
14+
"lint:ts": "eslint '{src,tests}/**/*.{js,ts,tsx}' --ignore-pattern '*.stories.tsx'",
15+
"start": "npm run start:storybook",
16+
"start:storybook": "storybook dev -p 3000 --no-open",
17+
"test:e2e": "E2E=true start-server-and-test 'npm run start:storybook' 3000 'jest -i --detectOpenHandles'",
18+
"test:e2e:ci": "CI=true npm run test:e2e",
19+
"test:spec": "jest --passWithNoTests",
20+
"test:spec:ci": "npm run test:spec"
21+
}
22+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { type JSX, type ReactNode, createContext, useContext } from 'react';
2+
import { Code } from '../../../../code/src';
3+
import { TEXT_PRESET, Text } from '../../../../text/src';
4+
5+
const CodeBlockContext = createContext(false);
6+
7+
const MarkdownCode = ({ children }: { children?: ReactNode }): JSX.Element => {
8+
const isBlock = useContext(CodeBlockContext);
9+
10+
if (isBlock) {
11+
return (
12+
<Code>
13+
{ children as string }
14+
</Code>
15+
);
16+
}
17+
18+
return (
19+
<Text
20+
as="code"
21+
preset={ TEXT_PRESET.code }>
22+
{ children }
23+
</Text>
24+
);
25+
};
26+
27+
const MarkdownPre = ({ children }: { children?: ReactNode }): JSX.Element => {
28+
return (
29+
<CodeBlockContext.Provider value={ true }>
30+
{ children }
31+
</CodeBlockContext.Provider>
32+
);
33+
};
34+
35+
MarkdownCode.displayName = 'MarkdownCode';
36+
MarkdownPre.displayName = 'MarkdownPre';
37+
38+
export {
39+
MarkdownCode,
40+
MarkdownPre,
41+
};

0 commit comments

Comments
 (0)