Skip to content

Commit ed461d9

Browse files
author
abdullahtilal26
committed
feat: add Noibu Help codes component in Makeswift
1 parent 42cb5a4 commit ed461d9

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

core/lib/makeswift/components.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import './components/site-header/register';
1414
import './components/site-theme/register';
1515
import './components/slideshow/register';
1616
import './components/sticky-sidebar/register';
17+
import './components/noibu/register';
1718

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from 'react';
2+
3+
interface NoibuHelpCodeProps {
4+
style?: string;
5+
}
6+
7+
interface NoibuRequestHelpCodeButtonProps {
8+
text?: string;
9+
style?: string;
10+
}
11+
12+
interface NoibuRequestHelpCodeLabelProps {
13+
style?: string;
14+
}
15+
16+
function parseInlineStyle(style?: string): Record<string, string> {
17+
const parsed: Record<string, string> = {};
18+
19+
if (style) {
20+
style.split(';').forEach((rule) => {
21+
const [prop, value] = rule.split(':');
22+
if (prop && value && !prop.trim().includes('-')) {
23+
parsed[prop.trim()] = value.trim();
24+
}
25+
});
26+
}
27+
28+
return parsed;
29+
}
30+
31+
export function NoibuAutomaticHelpCode({ style }: NoibuHelpCodeProps) {
32+
return (
33+
<div id="help-code-field" style={{ ...parseInlineStyle(style) }}>
34+
&nbsp;
35+
</div>
36+
);
37+
}
38+
39+
export function NoibuRequestHelpCodeButton({ text, style }: NoibuRequestHelpCodeButtonProps) {
40+
return (
41+
<button id="request-help-code" style={{ ...parseInlineStyle(style) }}>
42+
{text || 'Request Help Code'}
43+
</button>
44+
);
45+
}
46+
47+
export function NoibuRequestHelpCodeLabel({ style }: NoibuRequestHelpCodeLabelProps) {
48+
return (
49+
<div id="help-code-result" style={{ ...parseInlineStyle(style) }}>
50+
&nbsp;
51+
</div>
52+
);
53+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { TextInput } from '@makeswift/runtime/controls';
2+
import { runtime } from '~/lib/makeswift/runtime';
3+
import {
4+
NoibuAutomaticHelpCode,
5+
NoibuRequestHelpCodeButton,
6+
NoibuRequestHelpCodeLabel,
7+
} from './client';
8+
9+
runtime.registerComponent(NoibuAutomaticHelpCode, {
10+
type: 'Noibu - Automatic Help Code',
11+
label: 'Noibu - Automatic Help Code',
12+
props: {
13+
style: TextInput({ label: 'Custom style (inline CSS)', defaultValue: '' }),
14+
},
15+
});
16+
17+
runtime.registerComponent(NoibuRequestHelpCodeButton, {
18+
type: 'Noibu - Request Help Code Button',
19+
label: 'Noibu - Request Help Code Button',
20+
props: {
21+
text: TextInput({ label: 'Button text', defaultValue: 'Request Help Code' }),
22+
style: TextInput({ label: 'Custom style (inline CSS)', defaultValue: '' }),
23+
},
24+
});
25+
26+
runtime.registerComponent(NoibuRequestHelpCodeLabel, {
27+
type: 'Noibu - Request Help Code Label',
28+
label: 'Noibu - Request Help Code Label',
29+
props: {
30+
style: TextInput({ label: 'Custom style (inline CSS)', defaultValue: '' }),
31+
},
32+
});

0 commit comments

Comments
 (0)