Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom labels support #23

Merged
merged 2 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
};