Skip to content

Commit

Permalink
feat: add custom labels support (#23)
Browse files Browse the repository at this point in the history
* feat: add custom labels
* build: pin prettier to v3.1.0
  • Loading branch information
BearToCode authored Dec 16, 2023
1 parent 14be70b commit 1b75fe7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/src/pages/api/core.svelte.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ Type: `(html: string) => void`

HTML sanitizer. See [here]({base}/getting-started#sanitization) for more details.

### `labels`

Type: `Partial<CartaLabels>`

Can be used to provide custom text for labels in the editor.

# `CartaEditor` options

List of options that can be used in the `<CartaEditor>` component.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"husky": "^8.0.3",
"lint-staged": "^13.2.2",
"ora": "^6.3.0",
"prettier": "^3.1.0",
"prettier": "3.1.0",
"prettier-plugin-svelte": "^3.1.0",
"prettier-plugin-tailwindcss": "^0.5.7",
"semantic-release": "^20.1.3",
Expand Down
12 changes: 10 additions & 2 deletions packages/carta-md/src/lib/CartaEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import MarkdownInput from './internal/components/MarkdownInput.svelte';
import { debounce } from './internal/utils';
import type { TextAreaProps } from './internal/textarea-props';
import { DefaultCartaLabels, type CartaLabels } from './internal/labels';
export let carta: Carta;
export let theme = 'default';
Expand All @@ -15,6 +16,13 @@
export let placeholder = '';
export let textarea: TextAreaProps = {};
let userLabels: Partial<CartaLabels> = {};
export { userLabels as labels };
const labels: CartaLabels = {
...DefaultCartaLabels,
...userLabels
};
let width: number;
let selectedTab: 'write' | 'preview' = 'write';
let windowMode: 'tabs' | 'split';
Expand Down Expand Up @@ -99,14 +107,14 @@
on:click={() => (selectedTab = 'write')}
class={selectedTab === 'write' ? 'carta-active' : ''}
>
Write
{labels.writeTab}
</button>
<button
type="button"
on:click={() => (selectedTab = 'preview')}
class={selectedTab === 'preview' ? 'carta-active' : ''}
>
Preview
{labels.previewTab}
</button>
{/if}
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/carta-md/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export type { Prefix } from '$lib/internal/prefixes';
export * from '$lib/internal/carta';
export * from '$lib/internal/highlight';
export * from '$lib/internal/textarea-props';
export * from '$lib/internal/labels';
export * from './default.css?inline';
export * from './light.css?inline';
12 changes: 12 additions & 0 deletions packages/carta-md/src/lib/internal/labels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Labels that may appear in the editor.
*/
export interface CartaLabels {
writeTab: string;
previewTab: string;
}

export const DefaultCartaLabels: CartaLabels = {
writeTab: 'Write',
previewTab: 'Preview'
};

0 comments on commit 1b75fe7

Please sign in to comment.