فهرست منبع

[stdf]Update Tabs component. v0.4.3

dufu1991 2 سال پیش
والد
کامیت
5fb915dbc5

+ 5 - 5
packages/stdf/components/tabBar/TabBar.svelte

@@ -97,16 +97,16 @@
 	$: activeLeft = active * (tabW / labels.length) + tabW / labels.length / 2 - activeW / 2;
 </script>
 
-<div bind:clientWidth={tabW} class={`bg-white dark:bg-gray-800 relative ${injClass}`} style="padding-bottom: env(safe-area-inset-bottom);">
+<div bind:clientWidth={tabW} class="bg-white dark:bg-gray-800 relative {injClass}" style="padding-bottom: env(safe-area-inset-bottom);">
 	{#if line}
 		<div
-			class={`mx-auto rounded-full h-[2px] absolute transition-all bottom-px bg-primary dark:bg-dark ${activeInjClass}`}
-			style="width:{lineW < 1 ? tabW / labels.length : activeW < 2 ? 2 : activeW}px;left:{lineW < 1
+			class="mx-auto rounded-full h-[2px] absolute transition-all bottom-px bg-primary dark:bg-dark {activeInjClass}"
+			style="width: {lineW < 1 ? tabW / labels.length : activeW < 2 ? 2 : activeW}px;left: {lineW < 1
 				? active * (tabW / labels.length)
 				: activeLeft}px;"
 		/>
 	{/if}
-	<div class={`flex justify-between`}>
+	<div class="flex justify-between">
 		{#each labels as label, i}
 			<!-- svelte-ignore a11y-click-events-have-key-events -->
 			<!-- svelte-ignore a11y-no-static-element-interactions -->
@@ -117,7 +117,7 @@
 				} ${love ? 'text-lg' : 'text-sm'} ${tabInjClass} ${i === active && activeTabInjClass}`}
 			>
 				{#if label.icon}
-					<div class={`${!label.text && 'py-2'}`}>
+					<div class:py-2={!label.text}>
 						<i class:hidden={i !== active}>
 							<Icon
 								{...label.icon}

+ 33 - 29
packages/stdf/components/tabs/Tab.svelte

@@ -1,4 +1,5 @@
 <script>
+	import { onMount } from 'svelte';
 	import { createEventDispatcher } from 'svelte';
 	import Icon from '../icon/Icon.svelte';
 
@@ -52,8 +53,8 @@
 	export let duration = 'base';
 
 	/**
-	 * 布局,h/v,对应tabs的placement
-	 * layout,h/v,corresponding to placement of tabs
+	 * 布局,h/v,对应 tabs 的 position
+	 * layout, h/v, corresponding to position of tabs
 	 * @type {'h'|'v'}
 	 * @default 'h'
 	 */
@@ -103,23 +104,23 @@
 	 * 左右间距
 	 * left and right spacing
 	 * @type {'0'|'1'|'2'|'3'|'4'|'6'|'8'|'12'|'16'|'20'}
-	 * @default '4'
+	 * @default '2'
 	 */
-	export let mx = '4';
+	export let mx = '2';
 
 	const radiusObj = { none: 'rounded-none', base: 'rounded', xl: 'rounded-xl', full: 'rounded-full' };
 	const durationObj = { fast: 'duration-150', base: 'duration-300', slow: 'duration-500', slower: 'duration-1000' };
 	const mxClass = {
-		'0': ' mx-0',
-		'1': ' mx-1',
-		'2': ' mx-2',
-		'3': ' mx-3',
-		'4': ' mx-4',
-		'6': ' mx-6',
-		'8': ' mx-8',
-		'12': ' mx-12',
-		'16': ' mx-16',
-		'20': ' mx-20',
+		'0': 'mx-0',
+		'1': 'mx-1',
+		'2': 'mx-2',
+		'3': 'mx-3',
+		'4': 'mx-4',
+		'6': 'mx-6',
+		'8': 'mx-8',
+		'12': 'mx-12',
+		'16': 'mx-16',
+		'20': 'mx-20',
 	};
 	const dispatch = createEventDispatcher(); //事件派发器  event dispatcher
 
@@ -135,43 +136,46 @@
 	$: activeH = layout === 'h' ? tabH - 4 : (tabH - 4) / labels.length;
 	$: activeLeft = layout === 'h' ? 2 + active * ((tabW - 4) / labels.length) : 2;
 	$: activeTop = layout === 'h' ? (lineType ? tabH - 2 : 2) : 2 + active * ((tabH - 4) / labels.length);
+	onMount(() => {
+		console.log(333, activeW);
+	});
 </script>
 
 <div
 	bind:clientWidth={tabW}
 	bind:clientHeight={tabH}
-	class={`${lineType && layout !== 'v' ? '' : 'bg-black/5 dark:bg-white/10'} p-[2px] relative ${radiusObj[radius] || radiusObj.base}${
-		mxClass[mx] || mxClass['4']
-	} ${injClass}`}
+	class="{lineType && layout !== 'v' ? '' : 'bg-black/5 dark:bg-white/10'} p-0.5 relative {radiusObj[radius] || radiusObj.base} {mxClass[
+		mx
+	] || mxClass['2']} {injClass}"
 >
 	{#if lineType && layout !== 'v'}
 		<div class="absolute h-[2px] bg-black/5 dark:bg-white/5 w-full bottom-0" />
 	{/if}
 	<div
-		class={` ${lineType && layout !== 'v' ? '' : 'shadow dark:shadow-sm dark:shadow-white/10'} absolute transition-all ${
-			durationObj[duration] || durationObj.base
-		} ${radiusObj[radius] || radiusObj.base} ${
-			lineType && layout !== 'v' ? 'bottom-0 bg-black/50 dark:bg-white/50' : 'bg-white dark:bg-gray-950'
-		} ${activeInjClass}`}
-		style="width:{activeW}px;height:{lineType && layout !== 'v' ? 2 : activeH}px;left:{activeLeft}px;top:{activeTop}px"
+		class="{lineType && layout !== 'v' ? '' : 'shadow dark:shadow-sm dark:shadow-white/10'} absolute transition-all {durationObj[
+			duration
+		] || durationObj.base} {radiusObj[radius] || radiusObj.base} {lineType && layout !== 'v'
+			? 'bottom-0 bg-black/50 dark:bg-white/50'
+			: 'bg-white dark:bg-gray-950'} {activeInjClass}"
+		style="width: {activeW}px;height: {lineType && layout !== 'v' ? 2 : activeH}px;left: {activeLeft}px;top: {activeTop}px"
 	/>
-	<div class={`relative ${layout === 'h' ? 'flex justify-between' : 'px-4  whitespace-nowrap'}`}>
+	<div class="relative {layout === 'h' ? 'flex justify-between' : 'px-4 whitespace-nowrap'}">
 		{#each labels as label, i}
 			<!-- svelte-ignore a11y-click-events-have-key-events -->
 			<!-- svelte-ignore a11y-no-static-element-interactions -->
 			<div
-				class={`cursor-pointer flex-1 flex justify-center ${layout === 'h' ? 'py-1' : 'py-2'} font-medium ${
-					love ? 'text-lg' : 'text-sm'
-				} leading-6 ${radiusObj[radius] || radiusObj.base} ${tabInjClass} ${i === active ? activeTabInjClass : ''}`}
+				class="cursor-pointer flex-1 flex justify-center {layout === 'h' ? 'py-1' : 'py-2'} font-medium {love
+					? 'text-lg'
+					: 'text-sm'} leading-6 {radiusObj[radius] || radiusObj.base} {tabInjClass} {i === active ? activeTabInjClass : ''}"
 				on:click={() => clickTabFun(i)}
 			>
 				{#if label.icon}
-					<div class={`mr-[2px] ${durationObj[duration] || durationObj.base}`}>
+					<div class="mr-[2px] {durationObj[duration] || durationObj.base}">
 						<Icon {...label.icon} />
 					</div>
 				{/if}
 				{#if label.text}
-					<div class={`transition-all ${durationObj[duration] || durationObj.base}`}>{label.text}</div>
+					<div class="transition-all {durationObj[duration] || durationObj.base}">{label.text}</div>
 				{/if}
 			</div>
 		{/each}

+ 26 - 31
packages/stdf/components/tabs/Tabs.svelte

@@ -20,7 +20,7 @@
 	 * @property {'none'|'base'|'xl'|'full'} [radius] - 圆角风格 radius style
 	 * @property {'fast'|'base'|'slow'|'slower'} [duration] - 过渡时间 transition time
 	 * @property {'0'|'1'|'2'|'3'|'4'|'6'|'8'|'12'|'16'|'20'} [mx] - 左右间距 left and right margin
-	 * @property {'h'|'v'} [layout] - 布局,h/v,对应tabs的placement layout,h/v,corresponding to placement of tabs
+	 * @property {'h'|'v'} [layout] - 布局,h/v,对应tabs的position layout,h/v,corresponding to position of tabs
 	 * @property {Boolean} [love] - 是否使用爱心样式 whether to use heart style
 	 * @property {String} [injClass] - Tab 最外层注入 CSS 类 Tab outermost injection CSS class
 	 * @property {String} [tabInjClass] - Tab 注入 CSS 类 Tab injection CSS class
@@ -46,11 +46,11 @@
 
 	/**
 	 * 选项卡 Tab 位置
-	 * placement of tabs
+	 * Position of tabs
 	 * @type {'t'|'b'|'l'|'r'}
 	 * @default 't'
 	 */
-	export let placement = 't';
+	export let position = 't';
 
 	/**
 	 * 是否使用过渡动画
@@ -75,82 +75,77 @@
 		active = e.detail;
 		dispatch('change', active); //Tab点击时派发Tabs的change事件,active表示激活的Tab索引值,即labels索引值
 	};
-	let width = 0; //宽度
+	let width = window.innerWidth; //宽度
 
-	const durationObj = {
-		fast: 'duration-150',
-		base: 'duration-300',
-		slow: 'duration-500',
-		slower: 'duration-1000',
-	};
+	const durationObj = { fast: 'duration-150', base: 'duration-300', slow: 'duration-500', slower: 'duration-1000' };
 </script>
 
 {#if transition}
-	{#if placement === 't'}
+	{#if position === 't'}
 		<Tab {active} {duration} {...tab} on:clicktab={clickTabFun} />
 		<div class="overflow-hidden" bind:clientWidth={width}>
 			<div
-				class={`transition-all relative flex ${durationObj[duration] || durationObj.base}`}
-				style="width:{tab.labels.length * width}px;left:-{active * width}px"
+				class="transition-all relative flex {durationObj[duration] || durationObj.base}"
+				style="width: {tab.labels.length * width}px;left: -{active * width}px"
 			>
-				<slot {active}>暂无 Tabs content!</slot>
+				<slot {active}>Tabs content is empty!</slot>
 			</div>
 		</div>
-	{:else if placement === 'b'}
+	{:else if position === 'b'}
 		<div class="overflow-hidden" bind:clientWidth={width}>
 			<div
-				class={`transition-all relative flex ${durationObj[duration] || durationObj.base}`}
+				class="transition-all relative flex {durationObj[duration] || durationObj.base}"
 				style="width:{tab.labels.length * width}px;left:-{active * width}px"
 			>
-				<slot {active}>暂无 Tabs content!</slot>
+				<slot {active}>Tabs content is empty!</slot>
 			</div>
 		</div>
 		<Tab {active} {...tab} on:clicktab={clickTabFun} />
-	{:else if placement === 'l'}
+	{:else if position === 'l'}
 		<div class="flex">
 			<div>
 				<Tab {active} {...tab} on:clicktab={clickTabFun} layout="v" />
 			</div>
 			<div class="grow">
-				<slot {active}>暂无 Tabs content!</slot>
+				<slot {active}>Tabs content is empty!</slot>
 			</div>
 		</div>
-	{:else if placement === 'r'}
+	{:else if position === 'r'}
 		<div class="flex">
 			<div class="grow">
-				<slot {active}>暂无 Tabs content!</slot>
+				<slot {active}>Tabs content is empty!</slot>
 			</div>
 			<div>
 				<Tab {active} {...tab} on:clicktab={clickTabFun} layout="v" />
 			</div>
 		</div>
 	{:else}
-		<div>placement 参数错误!</div>
+		<div>position params error!</div>
 	{/if}
-{:else if placement === 't'}
+{:else if position === 't'}
 	<Tab {active} {duration} {...tab} on:clicktab={clickTabFun} />
-	<slot {active}>暂无 Tabs content!</slot>
-{:else if placement === 'b'}
-	<slot {active}>暂无 Tabs content!</slot>
+	<slot {active}>Tabs content is empty!</slot>
+{:else if position === 'b'}
+	<slot {active}>Tabs content is empty!</slot>
 	<Tab {active} {...tab} on:clicktab={clickTabFun} />
-{:else if placement === 'l'}
+{:else if position === 'l'}
 	<div class="flex">
 		<div>
 			<Tab {active} {...tab} on:clicktab={clickTabFun} layout="v" />
 		</div>
 		<div class="grow">
-			<slot {active}>暂无 Tabs content!</slot>
+			<slot {active}>Tabs content is empty!</slot>
 		</div>
 	</div>
-{:else if placement === 'r'}
+{:else if position === 'r'}
 	<div class="flex">
 		<div class="grow">
-			<slot {active}>暂无 Tabs content!</slot>
+			<slot {active}>Tabs content is empty!</slot>
 		</div>
 		<div>
 			<Tab {active} {...tab} on:clicktab={clickTabFun} layout="v" />
 		</div>
 	</div>
 {:else}
-	<div>placement 参数错误!</div>
+	<div>position params error!</div>
 {/if}

+ 3 - 6
packages/stdf/package.json

@@ -1,14 +1,11 @@
 {
 	"name": "stdf",
-	"version": "0.4.2",
+	"version": "0.4.3",
 	"description": "Mobile web component library based on Svelte and Tailwind",
 	"main": "./components/index.js",
 	"svelte": "./components/index.js",
-	"scripts": {
-		"dist": "node scripts/dist",
-		"test": "echo \"Error: no test specified\" && exit 1"
-	},
-	"author": "dufu1991",
+	"scripts": {},
+	"author": "any-tdf",
 	"funding": "https://stdf.design?fund",
 	"license": "MIT",
 	"homepage": "https://stdf.design",