Skip to content

Commit b0025d9

Browse files
tangjinzhouzkwolf
andauthored
feat: add typography (#3807)
* feat: add typography * fix: review typography * fix: review typography * feat: update typography * feat: update typography * fix: typography * test: update typography Co-authored-by: zkwolf <[email protected]>
1 parent 21bf0a3 commit b0025d9

30 files changed

+2145
-3
lines changed

.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"@typescript-eslint/no-unused-vars": [
3737
"error",
3838
{ "vars": "all", "args": "after-used", "ignoreRestSiblings": true }
39-
]
39+
],
40+
"@typescript-eslint/ban-ts-comment": 0
4041
}
4142
}
4243
],
+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import deselectCurrent from './toggle-selection';
2+
3+
interface Options {
4+
debug?: boolean;
5+
message?: string;
6+
format?: string; // MIME type
7+
onCopy?: (clipboardData: object) => void;
8+
}
9+
10+
const clipboardToIE11Formatting = {
11+
'text/plain': 'Text',
12+
'text/html': 'Url',
13+
default: 'Text',
14+
};
15+
16+
const defaultMessage = 'Copy to clipboard: #{key}, Enter';
17+
18+
function format(message: string) {
19+
const copyKey = (/mac os x/i.test(navigator.userAgent) ? '⌘' : 'Ctrl') + '+C';
20+
return message.replace(/#{\s*key\s*}/g, copyKey);
21+
}
22+
23+
function copy(text: string, options?: Options): boolean {
24+
let message,
25+
reselectPrevious,
26+
range,
27+
selection,
28+
mark,
29+
success = false;
30+
if (!options) {
31+
options = {};
32+
}
33+
const debug = options.debug || false;
34+
try {
35+
reselectPrevious = deselectCurrent();
36+
37+
range = document.createRange();
38+
selection = document.getSelection();
39+
40+
mark = document.createElement('span');
41+
mark.textContent = text;
42+
// reset user styles for span element
43+
mark.style.all = 'unset';
44+
// prevents scrolling to the end of the page
45+
mark.style.position = 'fixed';
46+
mark.style.top = 0;
47+
mark.style.clip = 'rect(0, 0, 0, 0)';
48+
// used to preserve spaces and line breaks
49+
mark.style.whiteSpace = 'pre';
50+
// do not inherit user-select (it may be `none`)
51+
mark.style.webkitUserSelect = 'text';
52+
mark.style.MozUserSelect = 'text';
53+
mark.style.msUserSelect = 'text';
54+
mark.style.userSelect = 'text';
55+
mark.addEventListener('copy', function(e) {
56+
e.stopPropagation();
57+
if (options.format) {
58+
e.preventDefault();
59+
if (typeof e.clipboardData === 'undefined') {
60+
// IE 11
61+
debug && console.warn('unable to use e.clipboardData');
62+
debug && console.warn('trying IE specific stuff');
63+
(window as any).clipboardData.clearData();
64+
const format =
65+
clipboardToIE11Formatting[options.format] || clipboardToIE11Formatting['default'];
66+
(window as any).clipboardData.setData(format, text);
67+
} else {
68+
// all other browsers
69+
e.clipboardData.clearData();
70+
e.clipboardData.setData(options.format, text);
71+
}
72+
}
73+
if (options.onCopy) {
74+
e.preventDefault();
75+
options.onCopy(e.clipboardData);
76+
}
77+
});
78+
79+
document.body.appendChild(mark);
80+
81+
range.selectNodeContents(mark);
82+
selection.addRange(range);
83+
84+
const successful = document.execCommand('copy');
85+
if (!successful) {
86+
throw new Error('copy command was unsuccessful');
87+
}
88+
success = true;
89+
} catch (err) {
90+
debug && console.error('unable to copy using execCommand: ', err);
91+
debug && console.warn('trying IE specific stuff');
92+
try {
93+
(window as any).clipboardData.setData(options.format || 'text', text);
94+
options.onCopy && options.onCopy((window as any).clipboardData);
95+
success = true;
96+
} catch (err) {
97+
debug && console.error('unable to copy using clipboardData: ', err);
98+
debug && console.error('falling back to prompt');
99+
message = format('message' in options ? options.message : defaultMessage);
100+
window.prompt(message, text);
101+
}
102+
} finally {
103+
if (selection) {
104+
if (typeof selection.removeRange == 'function') {
105+
selection.removeRange(range);
106+
} else {
107+
selection.removeAllRanges();
108+
}
109+
}
110+
111+
if (mark) {
112+
document.body.removeChild(mark);
113+
}
114+
reselectPrevious();
115+
}
116+
117+
return success;
118+
}
119+
120+
export default copy;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// copy from https://github.com/sudodoki/toggle-selection
2+
// refactor to esm
3+
const deselectCurrent = (): (() => void) => {
4+
const selection = document.getSelection();
5+
if (!selection.rangeCount) {
6+
return function() {};
7+
}
8+
let active = document.activeElement as any;
9+
10+
const ranges = [];
11+
for (let i = 0; i < selection.rangeCount; i++) {
12+
ranges.push(selection.getRangeAt(i));
13+
}
14+
15+
switch (
16+
active.tagName.toUpperCase() // .toUpperCase handles XHTML
17+
) {
18+
case 'INPUT':
19+
case 'TEXTAREA':
20+
active.blur();
21+
break;
22+
23+
default:
24+
active = null;
25+
break;
26+
}
27+
28+
selection.removeAllRanges();
29+
return function() {
30+
selection.type === 'Caret' && selection.removeAllRanges();
31+
32+
if (!selection.rangeCount) {
33+
ranges.forEach(function(range) {
34+
selection.addRange(range);
35+
});
36+
}
37+
38+
active && active.focus();
39+
};
40+
};
41+
export default deselectCurrent;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { computed, inject } from 'vue';
2+
import { defaultConfigProvider } from '../../config-provider';
3+
4+
export default (name: string, props: Record<any, any>) => {
5+
const configProvider = inject('configProvider', defaultConfigProvider);
6+
const prefixCls = computed(() => configProvider.getPrefixCls(name, props.prefixCls));
7+
return { configProvider, prefixCls };
8+
};

components/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ import { default as Descriptions } from './descriptions';
146146
import { default as PageHeader } from './page-header';
147147
import { default as Space } from './space';
148148

149+
import { default as Typography } from './typography';
150+
149151
const components = [
150152
Affix,
151153
Anchor,
@@ -210,6 +212,7 @@ const components = [
210212
PageHeader,
211213
Space,
212214
Image,
215+
Typography,
213216
];
214217

215218
const install = function(app: App) {
@@ -298,6 +301,7 @@ export {
298301
PageHeader,
299302
Space,
300303
Image,
304+
Typography,
301305
};
302306

303307
export default {

components/input/TextArea.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const TextAreaProps = {
1313
autosize: withUndefined(PropTypes.oneOfType([Object, Boolean])),
1414
autoSize: withUndefined(PropTypes.oneOfType([Object, Boolean])),
1515
showCount: PropTypes.looseBool,
16+
onCompositionstart: PropTypes.func,
17+
onCompositionend: PropTypes.func,
1618
};
1719

1820
export default defineComponent({

components/input/calculateNodeHeight.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,6 @@ export default function calculateNodeHeight(
155155
minHeight: `${minHeight}px`,
156156
maxHeight: `${maxHeight}px`,
157157
overflowY,
158+
resize: 'none',
158159
};
159160
}

components/style.ts

+1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,5 @@ import './page-header/style';
6161
import './form/style';
6262
import './space/style';
6363
import './image/style';
64+
import './typography/style';
6465
// import './color-picker/style';

components/style/mixins/typography.less

+9
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,12 @@
4747
@typography-title-margin-bottom
4848
);
4949
}
50+
.typography-title-5() {
51+
.typography-title(
52+
@heading-5-size,
53+
@typography-title-font-weight,
54+
1.5,
55+
@heading-color,
56+
@typography-title-margin-bottom
57+
);
58+
}

0 commit comments

Comments
 (0)