Skip to content

Commit 3d4e2aa

Browse files
committed
upgrade to 1.0.0v
1 parent 75fb7bc commit 3d4e2aa

File tree

4 files changed

+120
-13
lines changed

4 files changed

+120
-13
lines changed

README.md

+114-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,116 @@
1-
# Vue 3 + TypeScript + Vite
1+
# Vuejs Code Block
22

3-
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
3+
[![NPM version](https://img.shields.io/npm/v/vuejs-code-block.svg)](https://www.npmjs.com/package/vuejs-code-block)
44

5-
Learn more about the recommended Project Setup and IDE Support in the [Vue Docs TypeScript Guide](https://vuejs.org/guide/typescript/overview.html#project-setup).
5+
> [!IMPORTANT] Note
6+
> For now this package has default themes, but in the future, it will be fully unstyled, allowing you to style it however you like.
7+
8+
## Installation
9+
10+
To get started, install the package via npm:
11+
12+
```bash
13+
npm install vuejs-code-block
14+
```
15+
16+
Alternatively, if you're using Yarn:
17+
18+
```bash
19+
yarn add vuejs-code-block
20+
```
21+
22+
## Basic Usage
23+
24+
Once installed, you can start using the `CodeBlock` component in your `Vue 3` app to display syntax-highlighted code. Here’s a simple example:
25+
26+
```vue ts:line-numbers {1}
27+
<template>
28+
<CodeBlock
29+
theme="dark"
30+
:code="codeExample"
31+
language="javascript"
32+
class="custom-class"
33+
id="example-code-block" />
34+
</template>
35+
36+
<script setup lang="ts">
37+
import { CodeBlock } from 'vuejs-code-block';
38+
39+
const codeExample = `
40+
function greet(name) {
41+
console.log('Hello, ' + name);
42+
}
43+
44+
greet('World');
45+
`;
46+
</script>
47+
```
48+
49+
> [!WARNING] WARNING ❗
50+
> Make sure the content of the `codeExample` string does **NOT** have leading spaces.
51+
> The code should be formatted like this:
52+
>
53+
> ```ts
54+
> const codeExample = `
55+
> function greet(name) {
56+
> console.log('Hello, ' + name);
57+
> }
58+
>
59+
> greet('World');
60+
> `;
61+
> ```
62+
>
63+
> Avoid writing it with leading spaces like this:
64+
>
65+
> ```ts
66+
> const codeExample = `
67+
> function greet(name) {
68+
> console.log('Hello, ' + name);
69+
> }
70+
>
71+
> greet('World');
72+
> `;
73+
> ```
74+
>
75+
> Incorrect formatting may cause unexpected whitespace in the code block.
76+
77+
<!-- - **`codeClass`** (optional): A custom CSS class for the `<code>` element inside the block. This allows you to style the code content specifically. -->
78+
<!-- - **`linesHighlighted`** (optional): An array of line numbers to be highlighted. Accepts an array of strings or numbers (e.g., `[1, 3]` to highlight the 1st and 3rd lines). -->
79+
<!-- - **`wordsHighlighted`** (optional): An array of specific words to be highlighted within the code. Accepts an array of strings (e.g., `['console', 'log']`). -->
80+
81+
## Props:
82+
83+
| Prop | Type | Required | Default | Description |
84+
| ----------- | --------- | -------- | ------- | ----------------------------------------------------------------------- |
85+
| `code` | `string` | Yes | N/A | The code you want to display, passed as a string. |
86+
| `language` | `string` | Yes | N/A | Specifies the programming language for syntax highlighting. |
87+
| `theme` | `string` | Yes | N/A | Specifies the theme to be used for syntax highlighting (light or dark). |
88+
| `asElement` | `string` | No | `<pre>` | Defines the HTML element wrapping the code block (defaults to `<pre>`). |
89+
| `numbered` | `boolean` | No | `false` | Displays line numbers when set to `true`. |
90+
91+
<!-- ## Custom Styling
92+
93+
One of the key features of **vuejs-code-block** is that it provides **unstyled** components, allowing you to style them however you like. For example, using CSS or Tailwind classes:
94+
95+
```vue
96+
<template>
97+
<div class="p-4 bg-gray-800 rounded-lg">
98+
<CodeBlock
99+
theme="dark"
100+
:code="exampleCode"
101+
language="javascript" />
102+
</div>
103+
</template>
104+
105+
<script setup>
106+
import { CodeBlock } from 'vuejs-code-block';
107+
108+
const exampleCode = `function greet(name) {
109+
console.log('Hello, ' + name);
110+
}
111+
112+
greet('World');
113+
`;
114+
</script>
115+
```
116+
-->

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"type": "module",
33
"private": false,
44
"name": "vuejs-code-block",
5-
"version": "0.0.2-alpha.1",
5+
"version": "1.0.0",
66
"description": "A Vue 3 component of unstyled UI components to build powerful code blocks.",
77
"author": {
88
"name": "Ebraheem Alhetari",

src/App.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
language="python"
88
:numbered="true"
99
:show-header="true"
10-
file-name="ss">
10+
file-name="ss.py">
1111
</CodeBlock>
1212
</template>
1313

src/components/code-block/CodeBlock.vue

+4-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
v-bind="$attrs"
1010
:style="props.showHeader ? '' : 'padding-top: 1rem'">
1111
<!-- Header Component -->
12-
1312
<div
1413
v-if="props.showHeader"
1514
class="header">
@@ -42,13 +41,10 @@
4241
</svg>
4342
<svg
4443
v-else
44+
fill="currentColor"
4545
class="check-icon"
4646
viewBox="0 0 36 36">
4747
<path
48-
fill="#77B255"
49-
d="M36 32a4 4 0 0 1-4 4H4a4 4 0 0 1-4-4V4a4 4 0 0 1 4-4h28a4 4 0 0 1 4 4v28z"></path>
50-
<path
51-
fill="#FFF"
5248
d="M29.28 6.362a2.502 2.502 0 0 0-3.458.736L14.936 23.877l-5.029-4.65a2.5 2.5 0 1 0-3.394 3.671l7.209 6.666c.48.445 1.09.665 1.696.665c.673 0 1.534-.282 2.099-1.139c.332-.506 12.5-19.27 12.5-19.27a2.5 2.5 0 0 0-.737-3.458z"></path>
5349
</svg>
5450
</button>
@@ -141,7 +137,7 @@
141137
}
142138
143139
.vuejs-code-block pre .header {
144-
padding: 0.75rem 1rem;
140+
padding: 0.5rem 1rem;
145141
display: flex;
146142
align-items: center;
147143
justify-content: space-between;
@@ -153,8 +149,8 @@
153149
border-radius: 0.25rem;
154150
display: flex;
155151
gap: 0.5rem;
156-
padding: 0.5rem 1.5rem;
157-
padding-left: 0.25rem;
152+
/* padding: 0.5rem 1.5rem; */
153+
/* padding-left: 0.25rem; */
158154
}
159155
160156
.vuejs-code-block pre .header .file-name p {

0 commit comments

Comments
 (0)