Skip to content

Commit 382e366

Browse files
committed
v0.20
[site] start [snackui] spacing props
1 parent d22a343 commit 382e366

File tree

135 files changed

+30332
-13900
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+30332
-13900
lines changed

.prettierrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"trailingComma": "es5",
3+
"semi": false,
4+
"singleQuote": true,
5+
"arrowParens": "always",
6+
"printWidth": 100
7+
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export function Component(props) {
139139
// media query spread conditional + themes
140140
{...media.lg && {
141141
hoverStyle: {
142-
backgroundColor: theme.backgroundColorAlt
142+
backgroundColor: theme.bg2
143143
}
144144
}}
145145
/>

examples/nextjs/components/NonSSRForNow.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function Examples() {
2020
function Example(props: { alternate?: boolean; children?: any }) {
2121
const theme = useTheme()
2222
return (
23-
<HStack alignItems="center" padding={10} flex={1} backgroundColor={theme.backgroundColor}>
23+
<HStack alignItems="center" padding={10} flex={1} backgroundColor={theme.bg}>
2424
<Text color={theme.color}>Hello&nbsp;</Text>
2525
<Text color={props.alternate ? theme.altColor : theme.color}>from SnackUI</Text>
2626
{props.children}

package.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,23 @@
2929
"publish": "ultra -r --no-pretty npm publish"
3030
},
3131
"resolutions": {
32+
"webpack": "^5.58.1",
33+
"prettier": "2.4.1",
34+
"prettier-plugin-import-sort": "0.0.7",
3235
"react": "0.0.0-experimental-b1a1cb116-20210924",
3336
"react-dom": "0.0.0-experimental-b1a1cb116-20210924",
3437
"react-refresh": "0.0.0-experimental-b1a1cb116-20210924",
3538
"react-test-renderer": "0.0.0-experimental-b1a1cb116-20210924",
39+
"react-native-web": "0.17.5",
3640
"@testing-library/react": "13.0.0-alpha.1",
3741
"esbuild": "0.11.20"
3842
},
3943
"dependencies": {
4044
"esbuild-jest": "^0.5.0",
41-
"prettier": "^2.3.0",
42-
"prettier-plugin-import-sort": "^0.0.6",
43-
"react-native-web": "^0.15.6",
45+
"prettier": "^2.4.1",
46+
"prettier-plugin-import-sort": "^0.0.7",
47+
"import-sort-style-module": "^6.0.0",
48+
"react-native-web": "^0.17.5",
4449
"ultra-runner": "^3.10.5"
4550
},
4651
"devDependencies": {

packages/babel-plugin/src/index.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,16 @@ export default declare(function snackBabelPlugin(
118118
...options,
119119
sourcePath,
120120
disableThemes: true,
121-
getFlattenedNode(props) {
121+
getFlattenedNode({ isTextView }) {
122122
if (!hasImportedView) {
123123
hasImportedView = true
124124
root.unshiftContainer('body', importNativeView())
125125
}
126-
return props.isTextView ? '__ReactNativeText' : '__ReactNativeView'
126+
return isTextView ? '__ReactNativeText' : '__ReactNativeView'
127127
},
128128
onExtractTag(props) {
129129
assertValidTag(props.node)
130-
131130
const stylesExpr = t.arrayExpression([])
132-
133131
let finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []
134132

135133
for (const attr of props.attrs) {
@@ -145,7 +143,6 @@ export default declare(function snackBabelPlugin(
145143
)
146144
}
147145
}
148-
149146
switch (attr.type) {
150147
case 'style':
151148
const ident = addSheetStyle(attr.value, props.node)
@@ -172,7 +169,6 @@ export default declare(function snackBabelPlugin(
172169
}
173170

174171
props.node.attributes = finalAttrs
175-
176172
if (props.isFlattened) {
177173
props.node.attributes.push(
178174
t.jsxAttribute(t.jsxIdentifier('style'), t.jsxExpressionContainer(stylesExpr))
@@ -197,9 +193,7 @@ export default declare(function snackBabelPlugin(
197193

198194
// replace the null with our object
199195
sheetOuter.declarations[0].init.arguments[0] = sheetObject
200-
201196
root.unshiftContainer('body', sheetOuter)
202-
203197
if (shouldPrintDebug) {
204198
console.log('>>', generator(root.parent).code)
205199
}

packages/site/.gitignore

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# vercel
34+
.vercel
35+

packages/site/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello
+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// Inspired by https://github.com/rexxars/react-refractor
2+
import React from 'react';
3+
import refractor from 'refractor/core';
4+
import js from 'refractor/lang/javascript';
5+
import jsx from 'refractor/lang/jsx';
6+
import bash from 'refractor/lang/bash';
7+
import css from 'refractor/lang/css';
8+
import diff from 'refractor/lang/diff';
9+
import hastToHtml from 'hast-util-to-html';
10+
import rangeParser from 'parse-numeric-range';
11+
import highlightLine from '@lib/rehype-highlight-line';
12+
import highlightWord from '@lib/rehype-highlight-word';
13+
import { Pre } from './Pre';
14+
15+
refractor.register(js);
16+
refractor.register(jsx);
17+
refractor.register(bash);
18+
refractor.register(css);
19+
refractor.register(diff);
20+
21+
type PreProps = Omit<React.ComponentProps<typeof Pre>, 'css'>;
22+
23+
type CodeBlockProps = PreProps & {
24+
language: 'js' | 'jsx' | 'bash' | 'css' | 'diff';
25+
value: string;
26+
line?: string;
27+
css?: any;
28+
mode?: 'static' | 'typewriter' | 'interactive';
29+
showLineNumbers?: boolean;
30+
};
31+
32+
export const CodeBlock = React.forwardRef<HTMLPreElement, CodeBlockProps>(
33+
(_props, forwardedRef) => {
34+
const {
35+
language,
36+
value,
37+
line = '0',
38+
className = '',
39+
mode,
40+
css,
41+
variant,
42+
showLineNumbers,
43+
...props
44+
} = _props;
45+
let result = refractor.highlight(value, language);
46+
47+
result = highlightLine(result, rangeParser(line));
48+
49+
result = highlightWord(result);
50+
51+
// convert to html
52+
result = hastToHtml(result);
53+
54+
// TODO reset theme
55+
56+
const classes = `language-${language} ${className}`;
57+
58+
if (mode === 'typewriter') {
59+
return (
60+
<CodeTypewriter className={classes} css={css} variant={variant} value={result} {...props} />
61+
);
62+
}
63+
64+
return (
65+
<Pre
66+
ref={forwardedRef}
67+
className={classes}
68+
css={css}
69+
variant={variant}
70+
data-line-numbers={showLineNumbers}
71+
{...props}
72+
>
73+
<code className={classes} dangerouslySetInnerHTML={{ __html: result }} />
74+
</Pre>
75+
);
76+
}
77+
);
78+
79+
/**
80+
* recursively get all text nodes as an array for a given element
81+
*/
82+
function getTextNodes(node) {
83+
let childTextNodes = [];
84+
85+
if (!node.hasChildNodes()) return;
86+
87+
const childNodes = node.childNodes;
88+
for (let i = 0; i < childNodes.length; i++) {
89+
if (childNodes[i].nodeType == Node.TEXT_NODE) {
90+
childTextNodes.push(childNodes[i]);
91+
} else if (childNodes[i].nodeType == Node.ELEMENT_NODE) {
92+
Array.prototype.push.apply(childTextNodes, getTextNodes(childNodes[i]));
93+
}
94+
}
95+
96+
return childTextNodes;
97+
}
98+
99+
/**
100+
* given a text node, wrap each character in the
101+
* given tag.
102+
*/
103+
function wrapEachCharacter(textNode, tag, count) {
104+
const text = textNode.nodeValue;
105+
const parent = textNode.parentNode;
106+
107+
const characters = text.split('');
108+
characters.forEach(function (character, letterIndex) {
109+
const delay = (count + letterIndex) * 50;
110+
var element = document.createElement(tag);
111+
var characterNode = document.createTextNode(character);
112+
element.appendChild(characterNode);
113+
element.style.opacity = 0;
114+
element.style.transition = `all ease 0ms ${delay}ms`;
115+
116+
parent.insertBefore(element, textNode);
117+
118+
// skip a couple of frames to trigger transition
119+
requestAnimationFrame(() => requestAnimationFrame(() => (element.style.opacity = 1)));
120+
});
121+
122+
parent.removeChild(textNode);
123+
}
124+
125+
function CodeTypewriter({ value, className, css, variant, ...props }) {
126+
const wrapperRef = React.useRef(null);
127+
128+
React.useEffect(() => {
129+
const wrapper = wrapperRef.current;
130+
131+
if (wrapper) {
132+
var allTextNodes = getTextNodes(wrapper);
133+
134+
let count = 0;
135+
allTextNodes.forEach((textNode) => {
136+
wrapEachCharacter(textNode, 'span', count);
137+
count = count + textNode.nodeValue.length;
138+
});
139+
wrapper.style.opacity = 1;
140+
}
141+
142+
return () => (wrapper.innerHTML = value);
143+
}, []);
144+
145+
return (
146+
<Pre className={className} css={css} variant={variant} {...props}>
147+
<code
148+
ref={wrapperRef}
149+
style={{ opacity: 0 }}
150+
className={className}
151+
dangerouslySetInnerHTML={{ __html: value }}
152+
/>
153+
</Pre>
154+
);
155+
}

0 commit comments

Comments
 (0)