@popsure/dirty-swan 0.27.7 → 0.27.8-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7583,7 +7583,7 @@ module.exports = isEqual;
7583
7583
 
7584
7584
  var isEqual = lodash_isequal.exports;
7585
7585
 
7586
- var css_248z$p = ".style-module_container__2L4SP {\n position: relative;\n}\n\n.style-module_prefix__3jAFZ {\n position: absolute;\n left: 16px;\n top: 50%;\n transform: translateY(-50%);\n color: var(--ds-grey-400);\n transition: 0.3s top;\n}\n.style-module_prefix--with-error__1yTTM {\n color: var(--ds-red-500);\n}\n\n.style-module_input__1eJO5:not(:placeholder-shown) ~ .style-module_placeholder__1U2z0,\n.style-module_input__1eJO5:focus ~ .style-module_placeholder__1U2z0 {\n top: 7px;\n left: 16px;\n transform: translateY(0);\n font-size: 10px;\n line-height: 12px;\n opacity: 1;\n}\n\n.style-module_input__1eJO5:focus ~ .style-module_placeholder__1U2z0 {\n color: var(--ds-primary-500);\n}\n.style-module_input__1eJO5:focus ~ .style-module_placeholder--with-error__2ieRU {\n color: var(--ds-red-500);\n}\n\n.style-module_input__1eJO5:focus ~ .style-module_prefix__3jAFZ {\n color: var(--ds-primary-500);\n}\n.style-module_input__1eJO5:focus ~ .style-module_prefix--with-error__1yTTM {\n color: var(--ds-red-500);\n}\n\n.style-module_input__1eJO5:not(:placeholder-shown) ~ .style-module_prefix__3jAFZ,\n.style-module_input__1eJO5:focus ~ .style-module_prefix__3jAFZ {\n top: 28px;\n}\n\n.style-module_input__1eJO5 {\n box-sizing: border-box;\n padding-top: 9px;\n font-family: inherit;\n}\n.style-module_input--no-placeholder__3EGwh {\n padding-top: 0px;\n}\n.style-module_input--with-prefix__38e0j {\n padding-left: 32px !important;\n}\n\n.style-module_placeholder__1U2z0 {\n position: absolute;\n pointer-events: none;\n left: 16px;\n top: 50%;\n transform: translateY(-50%);\n transition: 0.3s ease all;\n color: var(--ds-grey-400);\n}\n.style-module_placeholder--with-prefix__2PquQ {\n left: 32px;\n}\n.style-module_placeholder--with-error__2ieRU {\n color: var(--ds-red-500);\n}\n\n.style-module_error__167Zc {\n margin-top: 4px;\n}";
7586
+ var css_248z$p = ".style-module_container__2L4SP {\n position: relative;\n}\n\n.style-module_prefix__3jAFZ {\n position: absolute;\n left: 16px;\n top: 50%;\n transform: translateY(-50%);\n color: var(--ds-grey-500);\n transition: 0.3s top;\n}\n.style-module_prefix--with-error__1yTTM {\n color: var(--ds-red-500);\n}\n\n.style-module_input__1eJO5:not(:placeholder-shown) ~ .style-module_placeholder__1U2z0,\n.style-module_input__1eJO5:focus ~ .style-module_placeholder__1U2z0 {\n top: 7px;\n left: 16px;\n transform: translateY(0);\n font-size: 10px;\n line-height: 12px;\n opacity: 1;\n}\n\n.style-module_input__1eJO5:focus ~ .style-module_placeholder__1U2z0 {\n color: var(--ds-primary-500);\n}\n.style-module_input__1eJO5:focus ~ .style-module_placeholder--with-error__2ieRU {\n color: var(--ds-red-500);\n}\n\n.style-module_input__1eJO5:focus ~ .style-module_prefix__3jAFZ {\n color: var(--ds-primary-500);\n}\n.style-module_input__1eJO5:focus ~ .style-module_prefix--with-error__1yTTM {\n color: var(--ds-red-500);\n}\n\n.style-module_input__1eJO5:not(:placeholder-shown) ~ .style-module_prefix__3jAFZ,\n.style-module_input__1eJO5:focus ~ .style-module_prefix__3jAFZ {\n top: 28px;\n}\n\n.style-module_input__1eJO5 {\n box-sizing: border-box;\n padding-top: 9px;\n font-family: inherit;\n}\n.style-module_input--no-placeholder__3EGwh {\n padding-top: 0px;\n}\n.style-module_input--with-prefix__38e0j {\n padding-left: 32px !important;\n}\n\n.style-module_placeholder__1U2z0 {\n position: absolute;\n pointer-events: none;\n left: 16px;\n top: 50%;\n transform: translateY(-50%);\n transition: 0.3s ease all;\n color: var(--ds-grey-500);\n}\n.style-module_placeholder--with-prefix__2PquQ {\n left: 32px;\n}\n.style-module_placeholder--with-error__2ieRU {\n color: var(--ds-red-500);\n}\n\n.style-module_error__167Zc {\n margin-top: 4px;\n}";
7587
7587
  var styles$o = {"container":"style-module_container__2L4SP","prefix":"style-module_prefix__3jAFZ","prefix--with-error":"style-module_prefix--with-error__1yTTM","input":"style-module_input__1eJO5","placeholder":"style-module_placeholder__1U2z0","placeholder--with-error":"style-module_placeholder--with-error__2ieRU","input--no-placeholder":"style-module_input--no-placeholder__3EGwh","input--with-prefix":"style-module_input--with-prefix__38e0j","placeholder--with-prefix":"style-module_placeholder--with-prefix__2PquQ","error":"style-module_error__167Zc"};
7588
7588
  styleInject(css_248z$p);
7589
7589
 
@@ -0,0 +1,9 @@
1
+ import React, { FunctionComponent } from 'react';
2
+ declare const Markdown: ({ children, customMDComponents, className, openLinksInNewTab, paragraphClassName, }: {
3
+ children: string;
4
+ customMDComponents?: Record<string, React.FunctionComponent<any>> | undefined;
5
+ className?: string | undefined;
6
+ openLinksInNewTab?: boolean | undefined;
7
+ paragraphClassName?: string | undefined;
8
+ }) => JSX.Element;
9
+ export default Markdown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@popsure/dirty-swan",
3
- "version": "0.27.7",
3
+ "version": "0.27.8-alpha",
4
4
  "author": "Vincent Audoire <vincent@getpopsure.com>",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -23,12 +23,15 @@
23
23
  "@popsure/public-models": "^1.0.1",
24
24
  "classnames": "^2.3.1",
25
25
  "dayjs": "^1.10.7",
26
+ "hastscript": "^7.0.2",
26
27
  "lodash.debounce": "^4.0.8",
27
28
  "lodash.isequal": "^4.5.0",
28
29
  "react-autosuggest": "^10.1.0",
29
30
  "react-day-picker": "^7.4.10",
30
31
  "react-dropzone": "^11.3.2",
32
+ "react-markdown": "^8.0.3",
31
33
  "react-scroll-sync": "^0.9.0",
34
+ "remark-directive": "^2.0.1",
32
35
  "sass": "^1.35.1",
33
36
  "signature_pad": "^3.0.0-beta.3"
34
37
  },
@@ -10,7 +10,7 @@
10
10
 
11
11
  transform: translateY(-50%);
12
12
 
13
- color: var(--ds-grey-400);
13
+ color: var(--ds-grey-500);
14
14
 
15
15
  transition: 0.3s top;
16
16
 
@@ -78,7 +78,7 @@
78
78
  transform: translateY(-50%);
79
79
  transition: 0.3s ease all;
80
80
 
81
- color: var(--ds-grey-400);
81
+ color: var(--ds-grey-500);
82
82
 
83
83
  &--with-prefix {
84
84
  left: 32px;
@@ -0,0 +1,78 @@
1
+ # Headers
2
+
3
+ The header options range from h1 to h4.
4
+
5
+ ```
6
+ # H1
7
+ ## H2
8
+ ### H3
9
+ #### H4
10
+ ```
11
+
12
+ # H1 Lorem ipsum non sunt qui sunt
13
+
14
+ ## H2 Lorem ipsum non sunt qui sunt
15
+
16
+ ### H3 Lorem ipsum non sunt qui sunt
17
+
18
+ #### H4 Lorem ipsum non sunt qui sunt
19
+
20
+ # Emphasis
21
+
22
+ ```
23
+ Emphasis or italics, use *asterisk* or _underscore_.
24
+ Strong emphasis or bold, use **asterisks** or __underscores__.
25
+ Combined emphasis, use **_asterisks and underscores_**.
26
+ ```
27
+
28
+ Emphasis or italics, use _asterisk_ or _underscore_.
29
+
30
+ Strong emphasis or bold, use **asterisks** or **underscores**.
31
+
32
+ Combined emphasis, use **_asterisks and underscores_**.
33
+
34
+ # Lists
35
+
36
+ ```
37
+ 1. First ordered list item
38
+ 2. Another item
39
+ 3. Actual numbers don't matter, just that it's a number
40
+ 4. And another item.
41
+
42
+ * Unordered list can use asterisks
43
+ - Or minuses
44
+ + Or pluses
45
+ ```
46
+
47
+ 1. First ordered list item
48
+ 2. Another item
49
+ 3. Actual numbers don't matter, just that it's a number
50
+ 4. And another item.
51
+
52
+ - Unordered list can use asterisks
53
+ - Or minuses
54
+ - Or pluses
55
+
56
+ # Links
57
+
58
+ For links markdown syntax should be used.
59
+
60
+ ```
61
+ [This is an inline link](https://feather-insurance.com)
62
+ ```
63
+
64
+ [This is an inline link](https://feather-insurance.com)
65
+
66
+ # Custom Markdown tags
67
+
68
+ When additional functionality needs to be added to the markdown component, custom tags can be used.
69
+
70
+ ```
71
+ Tags in the form of :mytag[value]{attributes} will be converted to the corresponding
72
+ custom HTML tags <mytag ...attributes>value<mytag>.
73
+
74
+ Custom styling for these tags can be provided by passing the customMDComponents prop
75
+ <Markdown customMDComponents={
76
+ mytag: ({ children }) => (<h1>{childrend}</h1>)
77
+ }>
78
+ ```
@@ -0,0 +1,22 @@
1
+ import { Meta, Preview } from '@storybook/addon-docs/blocks';
2
+
3
+ import Markdown from '.';
4
+ import example from './example.md';
5
+
6
+ <Meta title="JSX/Markdown" />
7
+
8
+ # Markdown
9
+
10
+ Display markdown text based on [react-markdown](https://github.com/remarkjs/react-markdown) with custom styling.
11
+
12
+ <Preview>
13
+ <Markdown>{example}</Markdown>
14
+ </Preview>
15
+
16
+ | attribute | unit | description | default value | required |
17
+ | ------------------ | ---------------------------------------------- | ------------------------------------------------ | ------------- | -------- |
18
+ | children | string | Markdown source to be rendered | n/a | true |
19
+ | customMDComponents | Record&ltstring, FunctionComponent&ltany&gt&gt | Styling functions for custom tags | n/a | false |
20
+ | className | string | Styles to be applied to the whole markdown block | '' | false |
21
+ | openLinksInNewTab | boolean | Whether the links should open in a new tab | false | false |
22
+ | paragraphClassName | string | Styles to be applied to paragraph tags | '' | false |
@@ -0,0 +1,139 @@
1
+ import { h } from 'hastscript/html.js';
2
+ import React, { FunctionComponent } from 'react';
3
+ import ReactMarkdown from 'react-markdown';
4
+ import remarkDirective from 'remark-directive';
5
+ import visit from 'unist-util-visit';
6
+
7
+ import styles from './styles.module.scss';
8
+
9
+ // The plugin function 'directiveToHTMLTag' is used in conjunction with 'remarkDirective' to parse custom markdown tags.
10
+
11
+ // It converts tags in the form of :mytag[value]{attributes} to the
12
+ // corresponding custom HTML tags <mytag ...attributes>value<mytag> .
13
+ // (NOTE: tag names are always converted to lowercase custom html tags)
14
+
15
+ // These can then be overridden by supplying the ReactMarkdown component with
16
+ // an entry in its 'components' property:
17
+ // <ReactMarkdown components={
18
+ // mytag: ({ children }) => (<h1>{childrend}</h1>)
19
+ // }>
20
+
21
+ // Without those plugins, it's only possible to override the standard html tags as listed here:
22
+ // https://github.com/remarkjs/react-markdown#appendix-b-components
23
+
24
+ const directiveToHTMLTag = () => {
25
+ return (tree: any) => {
26
+ // Visit the given tree and transform 'text-', 'leaf-' or 'containerDirectives' (= custom tags) as parsed by
27
+ // the remarkDirective plugin
28
+ visit(
29
+ tree,
30
+ ['textDirective', 'leafDirective', 'containerDirective'],
31
+ (node: any) => {
32
+ // Grab a reference to the data of the custom tag node
33
+ const data = node.data || (node.data = {});
34
+
35
+ // Create a HyperText Abstract Syntax Tree (HAST) from the node
36
+ const hast = h(node.name, node.attributes);
37
+
38
+ // Modify the node data with the resulting HAST's data to transform the node into something
39
+ // that ReactMarkdown can understand (custom html tag) and later replace with a custom component
40
+ data.hName = hast.tagName;
41
+ data.hProperties = hast.properties;
42
+ }
43
+ );
44
+ };
45
+ };
46
+
47
+ const Link = (openLinksInNewTab: boolean) => (props: any) => {
48
+ return openLinksInNewTab ? (
49
+ <a href={props.href} className="p-a" target="_blank" rel="noreferrer">
50
+ {props.children}
51
+ </a>
52
+ ) : (
53
+ <a href={props.href} className="p-a">
54
+ {props.children}
55
+ </a>
56
+ );
57
+ };
58
+
59
+ const Paragraph = (className: string) => (props: any) => {
60
+ return <p className={className || 'p-p mt8'}>{props.children}</p>;
61
+ };
62
+
63
+ const Heading = (props: any) => {
64
+ const { level } = props;
65
+
66
+ switch (level) {
67
+ case 1:
68
+ return <h1 className="p-h1 p--serif mt32">{props.children}</h1>;
69
+ case 2:
70
+ return <h2 className="p-h2 mt24">{props.children}</h2>;
71
+ case 3:
72
+ return <h3 className="p-h3 mt16">{props.children}</h3>;
73
+ case 4:
74
+ return <h4 className="p-h4 mt8">{props.children}</h4>;
75
+ default:
76
+ return <p>{props.children}</p>;
77
+ }
78
+ };
79
+
80
+ const UList = (props: any) => {
81
+ return <ul className={`p-p ${styles.ulist} mt8`}>{props.children}</ul>;
82
+ };
83
+
84
+ const OList = (props: any) => {
85
+ return <ol className={`p-p ${styles.olist} mt8`}>{props.children}</ol>;
86
+ };
87
+
88
+ const Strong = (props: any) => {
89
+ return <strong className="fw-bold">{props.children}</strong>;
90
+ };
91
+
92
+ const Italic = (props: any) => {
93
+ return <em className="fs-italic">{props.children}</em>;
94
+ };
95
+
96
+ const Code = (props: any) => {
97
+ return (
98
+ <div className={`bg-grey-200 p8 p-p--small my8 br2 ${styles.code}`}>
99
+ {props.children}
100
+ </div>
101
+ );
102
+ };
103
+
104
+ const Markdown = ({
105
+ children,
106
+ customMDComponents,
107
+ className = '',
108
+ openLinksInNewTab = false,
109
+ paragraphClassName = '',
110
+ }: {
111
+ children: string;
112
+ customMDComponents?: Record<string, FunctionComponent<any>>;
113
+ className?: string;
114
+ openLinksInNewTab?: boolean;
115
+ paragraphClassName?: string;
116
+ }) => (
117
+ <ReactMarkdown
118
+ children={children}
119
+ className={className}
120
+ components={{
121
+ a: Link(openLinksInNewTab),
122
+ p: Paragraph(paragraphClassName),
123
+ h1: Heading,
124
+ h2: Heading,
125
+ h3: Heading,
126
+ h4: Heading,
127
+ h5: Heading,
128
+ ol: OList,
129
+ ul: UList,
130
+ strong: Strong,
131
+ em: Italic,
132
+ code: Code,
133
+ ...customMDComponents,
134
+ }}
135
+ remarkPlugins={[remarkDirective, directiveToHTMLTag]}
136
+ />
137
+ );
138
+
139
+ export default Markdown;
@@ -0,0 +1,13 @@
1
+ .ulist {
2
+ list-style-type: disc;
3
+ list-style-position: inside;
4
+ }
5
+
6
+ .olist {
7
+ list-style-type: decimal;
8
+ list-style-position: inside;
9
+ }
10
+
11
+ .code {
12
+ font-family: monospace;
13
+ }