Skip to content

Commit

Permalink
refactor: use 'class' exclusively for buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Jan 23, 2025
1 parent 3b0795e commit f30bb66
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/myst-ext-button/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export const buttonRole: RoleSpec = {
const url = rawLabel ?? body;
const node: Link = {
type: 'link',
kind: 'button',
url,
children: [],
class: 'button', // TODO: allow users to extend this
};
if (modified) node.children = [{ type: 'text', value: modified.trim() }];
return [node];
Expand Down
16 changes: 9 additions & 7 deletions packages/myst-ext-button/tests/button.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import { describe, expect, it } from 'vitest';
import { buttonRole } from '../src';
import type { RoleData } from 'myst-common';
import { VFile } from 'vfile';

describe('Button component', () => {
it('should process button role correctly', () => {
const data: RoleData = { body: 'Click me<http://example.com>' };
const result = buttonRole.run(data);
const result = buttonRole.run(
{ name: 'button', body: 'Click me<http://example.com>' },
new VFile(),
);

expect(result).toEqual([
{
type: 'link',
kind: 'button',
class: 'button',
url: 'http://example.com',
children: [{ type: 'text', value: 'Click me' }],
},
]);
});

it('should process button role without label correctly', () => {
const data: RoleData = { body: 'http://example.com' };
const result = buttonRole.run(data);
const result = buttonRole.run({ name: 'button', body: 'http://example.com' }, new VFile());
expect(result).toEqual([
{
type: 'link',
kind: 'button',
class: 'button',
url: 'http://example.com',
children: [],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/myst-spec-ext/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export type CrossReference = SpecCrossReference & {
dataUrl?: string;
remoteBaseUrl?: string;
html_id?: string;
class?: Image['class'];
};

export type Link = SpecLink & {
Expand All @@ -284,7 +285,6 @@ export type Link = SpecLink & {
static?: true;
protocol?: string;
error?: true;
kind?: 'button';
class?: Image['class'];
};

Expand Down

0 comments on commit f30bb66

Please sign in to comment.