Skip to content

refactor:typography #6244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ import './result/style';
import './form/style';
import './space/style';
import './image/style';
import './typography/style';
// import './typography/style';
// import './color-picker/style';
4 changes: 2 additions & 2 deletions components/theme/interface/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import type { ComponentToken as TagComponentToken } from '../../tag/style';
// import type { ComponentToken as TimelineComponentToken } from '../../timeline/style';
import type { ComponentToken as TooltipComponentToken } from '../../tooltip/style';
// import type { ComponentToken as TransferComponentToken } from '../../transfer/style';
// import type { ComponentToken as TypographyComponentToken } from '../../typography/style';
import type { ComponentToken as TypographyComponentToken } from '../../typography/style';
// import type { ComponentToken as UploadComponentToken } from '../../upload/style';
// import type { ComponentToken as TourComponentToken } from '../../tour/style';
// import type { ComponentToken as QRCodeComponentToken } from '../../qrcode/style';
Expand Down Expand Up @@ -98,7 +98,7 @@ export interface ComponentTokenMap {
Tag?: TagComponentToken;
Tree?: {};
TreeSelect?: {};
// Typography?: TypographyComponentToken;
Typography?: TypographyComponentToken;
// Timeline?: TimelineComponentToken;
// Transfer?: TransferComponentToken;
// Tabs?: TabsComponentToken;
Expand Down
77 changes: 47 additions & 30 deletions components/typography/Editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import KeyCode from '../_util/KeyCode';
import TextArea from '../input/TextArea';
import EnterOutlined from '@ant-design/icons-vue/EnterOutlined';
import type { ExtractPropTypes, PropType } from 'vue';
import { defineComponent, ref, reactive, watch, onMounted, computed } from 'vue';
import { defineComponent, ref, reactive, watch, onMounted, toRefs } from 'vue';
import type { Direction } from '../config-provider';
import type { ChangeEventHandler } from '../_util/EventInterface';
import type { AutoSizeType } from '../input/inputProps';
import classNames from '../_util/classNames';

// CSSINJS
import useStyle from './style';

const editableProps = () => ({
prefixCls: String,
Expand All @@ -24,9 +28,11 @@ export type EditableProps = Partial<ExtractPropTypes<ReturnType<typeof editableP
const Editable = defineComponent({
compatConfig: { MODE: 3 },
name: 'Editable',
inheritAttrs: false,
props: editableProps(),
// emits: ['save', 'cancel', 'end', 'change'],
setup(props, { emit, slots }) {
setup(props, { emit, slots, attrs }) {
const { prefixCls } = toRefs(props);
const state = reactive({
current: props.value || '',
lastKeyCode: undefined,
Expand Down Expand Up @@ -109,34 +115,45 @@ const Editable = defineComponent({
function confirmChange() {
emit('save', state.current.trim());
}
const textAreaClassName = computed(() => ({
[`${props.prefixCls}`]: true,
[`${props.prefixCls}-edit-content`]: true,
[`${props.prefixCls}-rtl`]: props.direction === 'rtl',
[props.component ? `${props.prefixCls}-${props.component}` : '']: true,
}));
return () => (
<div class={textAreaClassName.value}>
<TextArea
ref={saveTextAreaRef}
maxlength={props.maxlength}
value={state.current}
onChange={onChange as ChangeEventHandler}
onKeydown={onKeyDown}
onKeyup={onKeyUp}
onCompositionstart={onCompositionStart}
onCompositionend={onCompositionEnd}
onBlur={onBlur}
rows={1}
autoSize={props.autoSize === undefined || props.autoSize}
/>
{slots.enterIcon ? (
slots.enterIcon({ className: `${props.prefixCls}-edit-content-confirm` })
) : (
<EnterOutlined class={`${props.prefixCls}-edit-content-confirm`} />
)}
</div>
);

// style
const [wrapSSR, hashId] = useStyle(prefixCls);

return () => {
const textAreaClassName = classNames(
{
[`${prefixCls.value}`]: true,
[`${prefixCls.value}-edit-content`]: true,
[`${prefixCls.value}-rtl`]: props.direction === 'rtl',
[props.component ? `${prefixCls.value}-${props.component}` : '']: true,
},
attrs.class,
hashId.value,
);

return wrapSSR(
<div {...attrs} class={textAreaClassName}>
<TextArea
ref={saveTextAreaRef}
maxlength={props.maxlength}
value={state.current}
onChange={onChange as ChangeEventHandler}
onKeydown={onKeyDown}
onKeyup={onKeyUp}
onCompositionstart={onCompositionStart}
onCompositionend={onCompositionEnd}
onBlur={onBlur}
rows={1}
autoSize={props.autoSize === undefined || props.autoSize}
/>
{slots.enterIcon ? (
slots.enterIcon({ className: `${props.prefixCls}-edit-content-confirm` })
) : (
<EnterOutlined class={`${props.prefixCls}-edit-content-confirm`} />
)}
</div>,
);
};
},
});

Expand Down
12 changes: 10 additions & 2 deletions components/typography/Typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import useConfigInject from '../config-provider/hooks/useConfigInject';
import classNames from '../_util/classNames';
import type { Direction } from '../config-provider';

// CSSINJS
import useStyle from './style';

export interface TypographyProps extends HTMLAttributes {
direction?: Direction;
prefixCls?: string;
Expand All @@ -24,6 +27,10 @@ const Typography = defineComponent<InternalTypographyProps>({
props: typographyProps() as any,
setup(props, { slots, attrs }) {
const { prefixCls, direction } = useConfigInject('typography', props);

// Style
const [wrapSSR, hashId] = useStyle(prefixCls);

return () => {
const {
prefixCls: _prefixCls,
Expand All @@ -32,17 +39,18 @@ const Typography = defineComponent<InternalTypographyProps>({
component: Component = 'article' as any,
...restProps
} = { ...props, ...attrs };
return (
return wrapSSR(
<Component
class={classNames(
prefixCls.value,
{ [`${prefixCls.value}-rtl`]: direction.value === 'rtl' },
attrs.class,
hashId.value,
)}
{...restProps}
>
{slots.default?.()}
</Component>
</Component>,
);
};
},
Expand Down
Loading