### Full Working Example with Timeline Data
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/INDEX.md
A complete example demonstrating the PrettyTimeline component with sample timeline data. This serves as a practical guide for implementation.
```vue
```
--------------------------------
### Installation
Source: https://github.com/guxuerui/pretty-timeline/blob/main/README.md
Instructions on how to install the pretty-timeline component using pnpm or npm.
```APIDOC
## Installation
```sh
# Install with pnpm
$ pnpm i pretty-timeline -S
# or npm
$ npm i pretty-timeline -S
```
```
--------------------------------
### Install Pretty Timeline
Source: https://github.com/guxuerui/pretty-timeline/blob/main/README.md
Install the pretty-timeline package using pnpm or npm.
```sh
# Install with pnpm
$ pnpm i pretty-timeline -S
# or npm
$ npm i pretty-timeline -S
```
--------------------------------
### NPM Installation
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/INDEX.md
Instructions for installing the pretty-timeline component library using NPM. Ensures the library is available for use in your project.
```bash
npm install pretty-timeline
# or
yarn add pretty-timeline
# or
pnpm add pretty-timeline
```
--------------------------------
### Install and Run Pretty Timeline Locally
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/installation-and-usage.md
Clone the repository, install dependencies using pnpm, and run the development server. Includes commands for building, testing, type checking, and linting.
```bash
git clone https://github.com/guxuerui/pretty-timeline.git
cd pretty-timeline
# Install dependencies
pnpm install
# Run development server
pnpm dev
# Build library
pnpm build
# Run tests
pnpm test
# Type checking
pnpm typecheck
# Linting
pnpm lint
```
--------------------------------
### Usage Example
Source: https://github.com/guxuerui/pretty-timeline/blob/main/README.md
An example of how to use the PrettyTimeline component in a Vue template, including data structure and props.
```APIDOC
## Usage Example
### Data Structure
```ts
import type { ITimeline } from 'pretty-timeline'
const timelineArr: ITimeline[] = [
{
isCollapsed: false,
year: '2022年',
title: '光阴长河',
list: [
{
date: '12月3日',
iconColor: 'green',
chipColor: '#26C1C9',
chipText: 'gxr chips',
subTitleColor: '#ec6a13',
subTitle: '新的一年开始了',
imgUrl: '/imgs/street.jpeg',
content: `
春日忆李白
白也诗无敌,飘然思不群。
清新庾开府,俊逸鲍参军。
渭北春天树,江东日暮云。
何时一尊酒,重与细论文。
我的Github
`,
},
// ... more list items
],
},
// ... more year items
]
```
### Template Usage
```html
```
```
--------------------------------
### Install Pretty Timeline with npm
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/installation-and-usage.md
Use npm to install the pretty-timeline package. This is the standard way to add Node.js packages to your project.
```bash
npm install pretty-timeline
```
--------------------------------
### Install Pretty Timeline with pnpm
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/installation-and-usage.md
Use pnpm to install the pretty-timeline package. pnpm is a fast, disk-space-efficient package manager.
```bash
pnpm install pretty-timeline
```
--------------------------------
### Install Pretty Timeline with yarn
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/installation-and-usage.md
Use yarn to install the pretty-timeline package. yarn is another popular package manager for JavaScript.
```bash
yarn add pretty-timeline
```
--------------------------------
### Install Pretty Timeline as a Plugin
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/INDEX.md
Use the plugin installer to integrate Pretty Timeline into your Vue application. This is an alternative to direct component import.
```typescript
import PrettyTimeline from 'pretty-timeline'
app.use(PrettyTimeline)
```
--------------------------------
### Animation and Transitions Example
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/INDEX.md
Illustrates the use of animations and transitions for elements like collapsing/expanding sections and rotating triangles. Enhances user experience with visual feedback.
```css
.timeline-item {
transition: all 0.3s ease-in-out;
}
.timeline-item.expanded {
/* styles for expanded state */
}
.triangle-icon {
transition: transform 0.3s ease;
}
.triangle-icon.rotated {
transform: rotate(180deg);
}
```
--------------------------------
### Full Vue.js Usage Example
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/installation-and-usage.md
Integrate the Pretty Timeline component into a Vue 3 application. This example demonstrates dynamic data binding and color customization.
```typescript
// components/TimelineExample.vue
Timeline
```
--------------------------------
### IList Usage Example
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/types.md
Demonstrates how to create an IList object for a timeline entry. Shows usage of various optional and required fields.
```typescript
import type { IList } from 'pretty-timeline'
const timelineEntry: IList = {
date: '3月15日',
iconColor: '#00ff00',
chipColor: '#0099ff',
chipText: 'Featured',
subTitleColor: '#ff6600',
subTitle: 'Important milestone',
imgUrl: '/milestone-photo.jpg',
content: '
This is a significant event in our timeline.
It supports HTML formatting.
'
}
```
--------------------------------
### PrettyTimeline Local Component Registration
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/api-reference-prettytimeline.md
Example of registering the PrettyTimeline component locally within a Vue application's setup function. Ensure 'pretty-timeline/dist/style.css' is imported for styling.
```typescript
import { ref } from 'vue'
import { PrettyTimeline } from 'pretty-timeline'
import type { ITimeline } from 'pretty-timeline'
import 'pretty-timeline/dist/style.css'
// Method 1: Local component registration
export default {
components: {
PrettyTimeline
},
setup() {
const timelineData = ref([
{
isCollapsed: false,
year: '2023年',
title: 'Major Events',
list: [
{
date: '6月27日',
iconColor: '#ec6a4f',
iconRight: '8%',
iconTop: '0%',
chipColor: '#26C1C9',
chipText: 'Release',
subTitleColor: '#ec6a13',
subTitle: 'Version 1.0 Released',
imgUrl: '/images/photo.jpg',
content: 'Initial release of the pretty-timeline component with full Vue 3 support.'
}
]
}
])
return { timelineData }
}
}
```
```vue
```
--------------------------------
### CSS Customization Example
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/INDEX.md
Illustrates how to customize the appearance of the PrettyTimeline component using CSS variables. Allows for theme adaptation and branding.
```css
.pretty-timeline {
/* Example: Change primary color */
--color-primary: #ff0000;
/* Example: Change line thickness */
--timeline-line-width: 3px;
}
```
--------------------------------
### Using isSafari() in Vue Setup
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/composables.md
Import and use the isSafari() composable within a Vue component's setup function to conditionally apply logic for Safari browsers.
```typescript
import { isSafari } from 'pretty-timeline'
export default {
setup() {
const usingSafari = isSafari()
if (usingSafari) {
console.log('Applying Safari-specific workarounds')
}
return { usingSafari }
}
}
```
--------------------------------
### isMobile() Composable Usage
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/composables.md
Demonstrates how to import and use the isMobile composable in a Vue 3 setup function to get a reactive boolean indicating if the client is on a mobile device.
```typescript
import { isMobile } from 'pretty-timeline'
export default {
setup() {
const isMobileDevice = isMobile()
return {
isMobileDevice
}
}
}
```
```html
Mobile version
Desktop version
```
--------------------------------
### PrettyTimeline Component Exports
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/api-reference-prettytimeline.md
Shows how to import the default plugin installer and the named PrettyTimeline component from the 'pretty-timeline' library.
```typescript
// Default export - plugin installer
export default {
install: (app: any): void => {
app.component('PrettyTimeline', PrettyTimeline)
}
}
// Named export - the component itself
export { PrettyTimeline }
```
--------------------------------
### ITimeline Usage Example
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/types.md
Example of how to structure data conforming to the ITimeline interface for use with the PrettyTimeline component. Ensure IList is also defined.
```typescript
import type { ITimeline } from 'pretty-timeline'
const timeline: ITimeline = {
isCollapsed: false,
year: '2024年',
title: 'Major Releases',
list: [
{
date: '1月15日',
subTitle: 'v2.0 Beta',
content: 'Beta version released for testing.'
},
{
date: '2月28日',
subTitle: 'v2.0 Stable',
content: 'Stable release with new features.'
}
]
}
```
--------------------------------
### Timeline Data Structure and Usage Example
Source: https://github.com/guxuerui/pretty-timeline/blob/main/README.md
Defines the structure for timeline data and demonstrates how to use it with the PrettyTimeline component.
```ts
import image from '/imgs/street.jpeg'
import type { ITimeline } from '~/types'
const timelineArr = ref([
{
isCollapsed: false,
year: '2022年',
title: '光阴长河',
list: [
{
date: '12月3日',
iconColor: 'green',
chipColor: '#26C1C9',
chipText: 'gxr chips',
subTitleColor: '#ec6a13',
subTitle: '新的一年开始了',
imgUrl: image,
content: "
春日忆李白
白也诗无敌,飘然思不群。
清新庾开府,俊逸鲍参军。
渭北春天树,江东日暮云。
何时一尊酒,重与细论文。
我的Github
",
},
{
date: '12月2日',
iconColor: '#fa1',
chipColor: '#26C',
chipText: '此时此刻, 恰如彼时彼刻',
subTitleColor: '#ec6a13',
subTitle: '进入12月了',
imgUrl: '',
content: "
菊
罗隐〔唐代〕
篱落岁云暮,数枝聊自芳。
雪裁纤蕊密,金拆小苞香。
千载白衣酒,一生青女霜。
春丛莫轻薄,彼此有行藏。
我的Github
",
},
],
},
{
isCollapsed: false,
year: '2021年',
title: '',
list: [
{
date: '12月2日',
chipText: '你好吗',
subTitle: '去年今日',
imgUrl: image,
content: "
秦淮杂诗·其八
王士祯〔清代〕
新歌细字写冰纨,小部君王带笑看。
千载秦淮呜咽水,不应仍恨孔都官。
",
},
],
},
])
```
```html
```
--------------------------------
### Composable Dependencies on @vueuse/core
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/composables.md
Demonstrates that composables like `useDark` and `isMobile` depend on the `@vueuse/core` library. Ensure this dependency is installed.
```typescript
// dark.ts
import { useDark, useToggle } from '@vueuse/core'
// isMobile.ts
import { resolveRef } from '@vueuse/core'
```
--------------------------------
### Importing Timeline Types
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/types.md
Demonstrates how to import the ITimeline and IList types from the 'pretty-timeline' library for use in your TypeScript projects. It also shows an example of defining timeline data structures.
```typescript
// Import from the main entry point
import type { IList, ITimeline } from 'pretty-timeline'
// Define your data structures
const myTimelines: ITimeline[] = [
{
isCollapsed: false,
year: '2023年',
title: 'Events',
list: [
{
date: '日期',
subTitle: '标题',
content: 'Content here'
}
]
}
]
```
--------------------------------
### Persist development mode using localStorage
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/composables.md
Implement custom functions to persist the development mode state to `localStorage` and load it on component mount. This example shows how to save the state when toggled and restore it when the application loads.
```typescript
import { isDev, toggleDev } from 'pretty-timeline'
// Save to localStorage on toggle
const persistedToggleDev = (force?: boolean) => {
const result = toggleDev(force)
localStorage.setItem('dev_mode', String(result))
return result
}
// Load from localStorage on setup
onMounted(() => {
const saved = localStorage.getItem('dev_mode')
if (saved === 'true') {
toggleDev(true)
}
})
```
--------------------------------
### Import and use isDev in Vue setup
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/composables.md
Import the `isDev` ref and expose it to the template for conditional rendering or displaying its state.
```typescript
import { isDev } from 'pretty-timeline'
export default {
setup() {
return { isDev }
}
}
```
--------------------------------
### Toggle development mode and log new state
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/composables.md
Import `isDev` and `toggleDev` to create functions that toggle the development mode and log the resulting state. This example shows how to use `toggleDev()` without arguments to flip the state.
```typescript
import { isDev, toggleDev } from 'pretty-timeline'
export default {
setup() {
const handleToggle = () => {
const newState = toggleDev()
console.log(`Dev mode is now: ${newState}`)
}
const enableDev = () => {
toggleDev(true)
}
return { isDev, handleToggle, enableDev }
}
}
```
--------------------------------
### Local Component Registration
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/INDEX.md
Example of registering the PrettyTimeline component locally within a Vue application. This is the standard way to use components in Vue 3.
```vue
```
--------------------------------
### Build Command
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/installation-and-usage.md
Execute this command to build the library for production. It generates optimized builds in the `dist/` directory.
```bash
pnpm build
```
--------------------------------
### Demo Application Entry Point
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/project-structure.md
Bootstraps the demo application using Vue Router and VueUse Head. Routes are generated by vite-plugin-pages.
```typescript
import { createHead } from '@vueuse/head'
import { createApp } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
import routes from 'virtual:generated-pages'
const app = createApp(App)
const head = createHead()
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes,
})
app.use(router)
app.use(head)
app.mount('#app')
```
--------------------------------
### Importing with Path Aliasing
Source: https://github.com/guxuerui/pretty-timeline/blob/main/src/pages/README.md
Shows how to use the '~/' alias to simplify imports, pointing to the './src/' directory.
```typescript
import { isDark } from '~/composables'
```
--------------------------------
### Importing with Relative Paths
Source: https://github.com/guxuerui/pretty-timeline/blob/main/src/pages/README.md
Demonstrates the use of relative paths for imports, which can become cumbersome.
```typescript
import { isDark } from '../../../../composables'
```
--------------------------------
### Initialize Theme Based on User Preference
Source: https://github.com/guxuerui/pretty-timeline/blob/main/index.html
This snippet checks for user preference for dark mode using `window.matchMedia` and `localStorage`. It applies the 'dark' class to the document's root element if the preference is set to dark or if the system prefers dark and no explicit light preference is set. This code should be run on page load.
```javascript
(function () {
const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
const setting = localStorage.getItem('color-schema') || 'auto';
if (setting === 'dark' || (prefersDark && setting !== 'light')) {
document.documentElement.classList.toggle('dark', true);
}
})();
```
--------------------------------
### Importing the Component
Source: https://github.com/guxuerui/pretty-timeline/blob/main/README.md
Demonstrates how to import the PrettyTimeline component for local or global use in a Vue 3 application.
```APIDOC
## Importing the Component
### Local Import
```ts
// In a .vue file
import { PrettyTimeline } from 'pretty-timeline'
import 'pretty-timeline/dist/style.css'
```
### Global Import
```ts
// In main.ts
import PrettyTimeline from 'pretty-timeline'
import 'pretty-timeline/dist/style.css'
// Register as a global component
app.use(PrettyTimeline)
// or
app.component('PrettyTimeline', PrettyTimeline)
```
```
--------------------------------
### Import Key Exports
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/00-START-HERE.md
Import the main component and necessary types for using Pretty Timeline.
```typescript
import { PrettyTimeline } from 'pretty-timeline'
import type { IList, ITimeline } from 'pretty-timeline'
import { isMobile, isDark, toggleDark } from 'pretty-timeline'
```
--------------------------------
### Import Pretty Timeline Globally
Source: https://github.com/guxuerui/pretty-timeline/blob/main/README.md
Import and register the component globally in your main application file.
```ts
// 在main.ts中
import PrettyTimeline from 'pretty-timeline'
import 'pretty-timeline/dist/style.css'
// 注册为全局组件使用
app.use(PrettyTimeline)
// or
app.component('PrettyTimeline', PrettyTimeline)
```
--------------------------------
### Project Dependency Tree
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/project-structure.md
Lists the production and development dependencies for the pretty-timeline project, including version information.
```text
pretty-timeline/
├── vue ^3.2.45
├── vue-router ^4.1.6
├── @vueuse/core v9.1.0
│ └── @vueuse/shared
├── @vueuse/head v0.7.9
├── axios ^1.2.0
├── canvas-confetti ^1.6.0
├── markdown-it-prism ^2.3.0
│ └── prismjs ^1.29.0
└── vite-plugin-vue-markdown 0.22.1
Dev Dependencies:
├── @vitejs/plugin-vue 3.2.0
├── vite ^3.2.7
├── vitest ^0.25.3
├── @vue/test-utils ^2.2.5
├── typescript ^4.9.3
├── unocss 0.47.5
│ └── @unocss/vite ^0.47.5
├── unplugin-auto-import ^0.12.0
├── unplugin-vue-components ^0.22.11
├── vite-plugin-pages ^0.27.1
└── vue-tsc ^1.0.11
```
--------------------------------
### PrettyTimeline Component API
Source: https://github.com/guxuerui/pretty-timeline/blob/main/_autodocs/INDEX.md
Reference for the PrettyTimeline component, the primary exported Vue component. Covers its props, internal methods, and setup.
```APIDOC
## PrettyTimeline Component
### Description
The main Vue component for rendering a timeline.
### Props
- **baseColor** (string) - Optional - The base color for the timeline.
- **timelineData** (Array