Skip to content
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

refactor: notification #1707

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mount } from '@vue/test-utils';
import { nextTick, ref } from 'vue';
import DNotification from '../src/notification';
import NotificationService from '../src/notification-service';
import { useNamespace } from '../../shared/hooks/use-namespace';
import { useNamespace } from '@devui/shared/utils';

const ns = useNamespace('notification', true);
describe('d-notification', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
import { defineComponent } from 'vue';
import { Icon } from '../../icon';
import { useNamespace } from '../../shared/hooks/use-namespace';
import { useNamespace } from '@devui/shared/utils';

export default defineComponent({
emits: ['click'],
setup(props, { emit }) {
const ns = useNamespace('notification');
return () => (
<div class={ns.e('icon-close')} onClick={(e) => emit('click', e)}>
<Icon name="close" size="14px" />
<svg
width="16px"
height="16px"
viewBox="0 0 14 14"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<polygon
id='path-1'
points='8.07106781 6065685425 10.8994949 3.82842712 12.3137085 5.24264069 9.48528137 8.07106781 12.3137085 10.8994949 12.3137085 10.8994949 10.8994949 12.3137085 8.07106781 9.48528137 5.24264069 12.3137085 3.82842712 10.8994949 6.65685425 8.07106781 3.82842712 5.24264069'
></polygon>
</defs>
<g id='error' stroke='none' stroke-width="1" fill='none' fill-rule='evenodd'>
<mask id='mask-2' fill='white'>
<use xlink:href='#path-1'></use>
</mask>
<use id='Mask' class="devui-toast-close-icon" xlink:href="#path-1"></use>
</g>
</svg>
</div>
);
},
Expand Down
27 changes: 14 additions & 13 deletions packages/devui-vue/devui/notification/src/notification-icons.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useNamespace } from '../../shared/hooks/use-namespace';
import { useNamespace } from '@devui/shared/utils';

const ns = useNamespace('notification');

Expand Down Expand Up @@ -58,19 +58,20 @@ export function InfoIcon(): JSX.Element {
export function ErrorIcon(): JSX.Element {
return (
<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" {...XLINK}>
<defs>
<polygon
id="path-e"
points={`8.07106781 6.65685425 10.8994949 3.82842712 12.3137085 5.24264069 9.48528137 8.07106781 12.3137085
10.8994949 10.8994949 12.3137085 8.07106781 9.48528137 5.24264069 12.3137085 3.82842712 10.8994949 6.65685425
8.07106781 3.82842712 5.24264069 5.24264069 3.82842712`}></polygon>
</defs>
<g id="error" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<mask id="mask-2" fill="white">
<use {...XLINK_HREF}></use>
</mask>
<use id="Mask" class={ns.e('image-error-path')} {...XLINK_HREF}></use>
<g stroke='none' stroke-width="1" fill='none' fill-rule='evenodd'>
<circle cx="8" cy="8" r="8"></circle>
<path
class={ns.e('image-error-path')}
d={`M11.5355339,4.46446609,C11.9260582,4.85499039 11.9260582,5.48815536 11.5355339,5.87867966 L9.41421356,8 L11.5355339,10.1213203
C11.9260582,10.5118446 11.9260582,11.1450096 11.5355339,11.5355339 C11.1450096,11.9260582 10.5118446,11.9260582 10.1213203,11.5355339
L8,9.41421356 L5.87867966,11.5355339 C5.48815536,11.9260582 4.85499039,11.9260582 4.46446609,11.5355339 C4.0739418,11.1450096
4.0739418,10.5118446 4.46446609,10.1213203 L6.58578644,8 L4.46446609,5.87867966 C4.0739418,5.48815536 4.0739418,4.85499039
4.46446609,4.46446609 C4.85499039,4.0739418 5.48815536,4.0739418 5.87867966,4.46446609 L8,6.58578644 L10.1213203,4.46446609
C10.5118446,4.0739418 11.1450096,4.0739418 11.5355339,4.46446609 Z`}
></path>
</g>


</svg>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { computed, defineComponent, toRefs } from 'vue';
import type { PropType } from 'vue';
import { NotificationType } from './notification-types';
import { SuccessIcon, WarningIcon, InfoIcon, ErrorIcon } from './notification-icons';
import { useNamespace } from '../../shared/hooks/use-namespace';
import { useNamespace } from '@devui/shared/utils';

export default defineComponent({
props: {
Expand Down
28 changes: 21 additions & 7 deletions packages/devui-vue/devui/notification/src/notification.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}
}

.#{$devui-prefix}-notification-item-container {
.#{$devui-prefix}-notification__item-container {
position: relative;
margin: 0 0 8px 0;
opacity: 0.95;
Expand All @@ -45,16 +45,17 @@
right: 10px;
cursor: pointer;

& i.icon {
color: $devui-light-text !important;
.devui-toast-close-icon {
fill: $devui-light-text ;
}
}

.#{$devui-prefix}-notification__title {
font-size: $devui-font-size-card-title;
padding: 0 0 calc(0.5em - 2px) 0;
font-size: $devui-font-size-lg;
padding: 0 0 4px 0;
display: block;
font-weight: 700;
line-height: 1.5;
}

.#{$devui-prefix}-notification__image {
Expand Down Expand Up @@ -101,9 +102,21 @@
.#{$devui-prefix}-notification__message {
margin-left: 20px;

&.no-title {
margin-left: 0;

.#{$devui-prefix}-notification__title {
padding: 0;
}

.#{$devui-prefix}-notification__content {
margin-top: 0;
}
}

.#{$devui-prefix}-notification__content {
font-size: $devui-font-size;
margin-top: 4px;
line-height: 1.5;
}
}

Expand All @@ -112,8 +125,9 @@
}

.#{$devui-prefix}-notification__message p {
font-size: $devui-font-size;
margin: 0;
margin-top: 4px;
line-height: 1.5;
}

.notification-fade {
Expand Down
11 changes: 6 additions & 5 deletions packages/devui-vue/devui/notification/src/notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@ import { notificationProps, NotificationProps } from './notification-types';
import Close from './notification-icon-close';
import TypeIcon from './notification-image';
import { useNotification, useEvent } from './use-notification';
import { useNamespace } from '../../shared/hooks/use-namespace';
import { useNamespace } from '@devui/shared/utils';
import './notification.scss';

export default defineComponent({
name: 'DNotification',
inheritAttrs:false,
props: notificationProps,
emits: ['update:modelValue', 'destroy'],
setup(props: NotificationProps, { emit, slots }) {
setup(props: NotificationProps, { emit, slots ,attrs}) {
const { modelValue, title, type } = toRefs(props);
const { classes } = useNotification(props);
const { interrupt, removeReset, close, handleDestroy } = useEvent(props, emit);
const ns = useNamespace('notification');
return () => (
<Transition name="notification-fade" onAfterLeave={handleDestroy}>
{modelValue.value && (
<div class={ns.b()} onClick={withModifiers(() => ({}), ['stop'])} onPointerup={withModifiers(() => ({}), ['stop'])}>
<div class={ns.b()} onClick={withModifiers(() => ({}), [''])} onPointerup={withModifiers(() => ({}), ['stop'])} {...attrs}>
<div class={classes.value} onMouseenter={interrupt} onMouseleave={removeReset}>
<div class={ns.e('item')}>
<Close onClick={close} />
{title.value && <TypeIcon type={type.value} />}
<div class={ns.e('message')}>
<div class={[ns.e('message'),{'no-title':props.title === ''}]}>
<span class={ns.e('title')}>{title.value}</span>
<span class={ns.e('content')}>{slots.default?.()}</span>
<p class={ns.e('content')}>{slots.default?.()}</p>
</div>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions packages/devui-vue/devui/notification/src/use-notification.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { computed, watch } from 'vue';
import type { ComputedRef } from 'vue';
import { NotificationProps, EmitEventFn, VoidFn } from './notification-types';
import { useNamespace } from '@devui/shared/utils';

const ns= useNamespace('notification')
export function useNotification(props: NotificationProps): { classes: ComputedRef<Record<string, boolean>> } {
const classes = computed(() => ({
'devui-notification-item-container': true,
[`devui-notification-message-${props.type}`]: true,
[ns.e('item-container')]:true,
[ns.em('message',props.type)]:true,
}));

return { classes };
Expand Down