Skip to content
Open
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
1 change: 1 addition & 0 deletions core/lib/makeswift/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import './components/site-header/register';
import './components/site-theme/register';
import './components/slideshow/register';
import './components/sticky-sidebar/register';
import './components/noibu/register';

import { MakeswiftComponentType } from '@makeswift/runtime';

Expand Down
51 changes: 51 additions & 0 deletions core/lib/makeswift/components/noibu/client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
interface NoibuHelpCodeProps {
style?: string;
}

interface NoibuRequestHelpCodeButtonProps {
text?: string;
style?: string;
}

interface NoibuRequestHelpCodeLabelProps {
style?: string;
}

function parseInlineStyle(style?: string): Record<string, string> {
const parsed: Record<string, string> = {};

if (style) {
style.split(';').forEach((rule) => {
const [prop, value] = rule.split(':');
if (prop && value && !prop.trim().includes('-')) {
parsed[prop.trim()] = value.trim();
}
});
}

return parsed;
}

export function NoibuAutomaticHelpCode({ style }: NoibuHelpCodeProps) {
return (
<div id="help-code-field" style={{ ...parseInlineStyle(style) }}>
&nbsp;
</div>
);
}

export function NoibuRequestHelpCodeButton({ text, style }: NoibuRequestHelpCodeButtonProps) {
return (
<button id="request-help-code" style={{ ...parseInlineStyle(style) }}>
{text || 'Request Help Code'}
</button>
);
}

export function NoibuRequestHelpCodeLabel({ style }: NoibuRequestHelpCodeLabelProps) {
return (
<div id="help-code-result" style={{ ...parseInlineStyle(style) }}>
&nbsp;
</div>
);
}
32 changes: 32 additions & 0 deletions core/lib/makeswift/components/noibu/register.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { TextInput } from '@makeswift/runtime/controls';
import { runtime } from '~/lib/makeswift/runtime';
import {
NoibuAutomaticHelpCode,
NoibuRequestHelpCodeButton,
NoibuRequestHelpCodeLabel,
} from './client';

runtime.registerComponent(NoibuAutomaticHelpCode, {
type: 'Noibu - Automatic Help Code',
label: 'Noibu - Automatic Help Code',
props: {
style: TextInput({ label: 'Custom style (inline CSS)', defaultValue: '' }),
},
});

runtime.registerComponent(NoibuRequestHelpCodeButton, {
type: 'Noibu - Request Help Code Button',
label: 'Noibu - Request Help Code Button',
props: {
text: TextInput({ label: 'Button text', defaultValue: 'Request Help Code' }),
style: TextInput({ label: 'Custom style (inline CSS)', defaultValue: '' }),
},
});

runtime.registerComponent(NoibuRequestHelpCodeLabel, {
type: 'Noibu - Request Help Code Label',
label: 'Noibu - Request Help Code Label',
props: {
style: TextInput({ label: 'Custom style (inline CSS)', defaultValue: '' }),
},
});