-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24e507f
commit e155e92
Showing
13 changed files
with
273 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; | ||
import KPageHeader from '../src'; | ||
|
||
let host; | ||
|
||
const initHost = () => { | ||
host = globalThis.document.createElement('div'); | ||
host.setAttribute('id', 'host'); | ||
globalThis.document.body.appendChild(host); | ||
}; | ||
beforeEach(() => { | ||
initHost(); | ||
vi.useFakeTimers(); | ||
}); | ||
afterEach(() => { | ||
host.remove(); | ||
vi.useRealTimers(); | ||
}); | ||
|
||
describe('Test: KPageHeader', () => { | ||
test('props: cls', async () => { | ||
const instance = new KPageHeader({ | ||
target: host, | ||
props: { | ||
cls: 'k-page-header--test' | ||
} | ||
}); | ||
expect(instance).toBeTruthy(); | ||
expect(host!.innerHTML.includes('k-page-header--test')).toBeTruthy(); | ||
expect(host.innerHTML).matchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "@ikun-ui/page-header", | ||
"version": "0.1.0", | ||
"type": "module", | ||
"main": "src/index.ts", | ||
"types": "src/index.d.ts", | ||
"svelte": "src/index.ts", | ||
"keywords": [ | ||
"svelte", | ||
"svelte3", | ||
"web component", | ||
"component", | ||
"react", | ||
"vue", | ||
"svelte-kit", | ||
"dx" | ||
], | ||
"files": [ | ||
"dist", | ||
"package.json" | ||
], | ||
"scripts": { | ||
"build": "npm run build:js && npm run build:svelte", | ||
"build:js": "tsc -p . --outDir dist/ --rootDir src/", | ||
"build:svelte": "svelte-strip strip src/ dist", | ||
"publish:pre": "node ../../scripts/pre-publish.js", | ||
"publish:npm": "pnpm run publish:pre && pnpm publish --no-git-checks --access public" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"main": "dist/index.js", | ||
"module": "dist/index.js", | ||
"svelte": "dist/index.js", | ||
"types": "dist/index.d.ts" | ||
}, | ||
"dependencies": { | ||
"@ikun-ui/icon": "workspace:*", | ||
"@ikun-ui/divider": "workspace:*", | ||
"@ikun-ui/utils": "workspace:*", | ||
"baiwusanyu-utils": "^1.0.16", | ||
"clsx": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@tsconfig/svelte": "^5.0.2", | ||
"svelte-strip": "^2.0.0", | ||
"tslib": "^2.6.2", | ||
"typescript": "^5.3.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<script lang="ts"> | ||
import { getPrefixCls } from '@ikun-ui/utils'; | ||
import { clsx } from 'clsx'; | ||
import type { KPageHeaderProps } from './types'; | ||
import { KIcon } from '@ikun-ui/icon'; | ||
import { KDivider } from '@ikun-ui/divider'; | ||
import { createEventDispatcher } from 'svelte'; | ||
export let title: KPageHeaderProps['title'] = ''; | ||
export let icon: KPageHeaderProps['icon'] = 'i-carbon-arrow-left'; | ||
export let content: KPageHeaderProps['content'] = ''; | ||
export let cls: KPageHeaderProps['cls'] = undefined; | ||
export let attrs: KPageHeaderProps['attrs'] = {}; | ||
const dispatch = createEventDispatcher(); | ||
function handleClick() { | ||
dispatch('back'); | ||
} | ||
const prefixCls = getPrefixCls('page-header'); | ||
$: cnames = clsx( | ||
prefixCls, | ||
{ | ||
[`${prefixCls}--has-breadcrumb`]: !!$$slots.breadcrumb, | ||
[`${prefixCls}--has-extra`]: !!$$slots.extra, | ||
[`${prefixCls}--contentful`]: !!$$slots.default | ||
}, | ||
cls | ||
); | ||
$: breadcrumbCls = clsx(`${prefixCls}__breadcrumb`); | ||
$: headCls = clsx(`${prefixCls}__head`); | ||
$: leftCls = clsx(`${prefixCls}__left`); | ||
$: backCls = clsx(`${prefixCls}__back`); | ||
$: iconCls = clsx(`${prefixCls}__icon`); | ||
$: titleCls = clsx(`${prefixCls}__title`); | ||
$: contentCls = clsx(`${prefixCls}__content`); | ||
$: extraCls = clsx(`${prefixCls}--extra`); | ||
$: mainCls = clsx(`${prefixCls}--main`); | ||
</script> | ||
|
||
<div class={cnames} {...$$restProps} {...attrs}> | ||
{#if $$slots.breadcrumb} | ||
<div class={breadcrumbCls}> | ||
<slot name="breadcrumb" /> | ||
</div> | ||
{/if} | ||
<div class={headCls}> | ||
<div class={leftCls}> | ||
<div class={backCls} role="button" tabindex="0" aria-hidden="true" on:click={handleClick}> | ||
{#if icon || $$slots.icon} | ||
<div aria-label={title || 'Back'} class={iconCls}> | ||
<slot name="icon"> | ||
<KIcon width="16px" height="16px" {icon}></KIcon> | ||
</slot> | ||
</div> | ||
{/if} | ||
<div class={titleCls}> | ||
<slot name="title">{title || 'Back'}</slot> | ||
</div> | ||
</div> | ||
<KDivider direction="vertical" /> | ||
<div class={contentCls}> | ||
<slot name="content">{content}</slot> | ||
</div> | ||
</div> | ||
|
||
{#if $$slots.extra} | ||
<div class={extraCls}> | ||
<slot name="extra" /> | ||
</div> | ||
{/if} | ||
</div> | ||
|
||
{#if $$slots.default} | ||
<div class={mainCls} data-pager-header="main"> | ||
<slot /> | ||
</div> | ||
{/if} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/// <reference types="./types" /> | ||
import PageHeader from './index.svelte'; | ||
export { PageHeader as KPageHeader }; | ||
export default PageHeader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/// <reference types="svelte" /> | ||
import type { ClassValue } from 'clsx'; | ||
export type KPageHeaderProps = { | ||
icon: string; | ||
title: string; | ||
content: string; | ||
cls: ClassValue; | ||
attrs: Record<string, string>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "@tsconfig/svelte/tsconfig.json", | ||
|
||
"compilerOptions": { | ||
"noImplicitAny": true, | ||
"strict": true, | ||
"declaration": true | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.svelte"], | ||
"exclude": ["node_modules/*", "**/*.spec.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.