From 3d7ed1124b4339ed8bbace5e47607918afc3e858 Mon Sep 17 00:00:00 2001 From: KazumaOhashi Date: Tue, 13 Aug 2024 10:41:59 +0900 Subject: [PATCH 1/4] Add Pulldown component --- src/components/Pulldown.module.css | 27 ++++++++++++++++++++++ src/components/Pulldown.tsx | 36 ++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/components/Pulldown.module.css create mode 100644 src/components/Pulldown.tsx diff --git a/src/components/Pulldown.module.css b/src/components/Pulldown.module.css new file mode 100644 index 0000000..a04fd96 --- /dev/null +++ b/src/components/Pulldown.module.css @@ -0,0 +1,27 @@ +.label { + font-size: 15px; + font-weight: 700; + margin-bottom: 8px; +} + +.frame { + display: flex; + width: 100%; +} + +.helpText { + color: rgb(148, 148, 148); + font-size: 13px; + font-weight: 400; + margin-top: 8px; + margin-bottom: 8px; +} + +.select { + padding: 4px 12px; + line-height: 24px; + font-size: 12px; + font-weight: 400; + border: solid 1px #ddd; + border-radius: 5px; +} diff --git a/src/components/Pulldown.tsx b/src/components/Pulldown.tsx new file mode 100644 index 0000000..009a52c --- /dev/null +++ b/src/components/Pulldown.tsx @@ -0,0 +1,36 @@ +import React from 'react' +import styles from './Pulldown.module.css' + +interface PulldownProps { + label: string + helpText?: string + value: number|string + onChange: (event: React.ChangeEvent) => void + options: { label: string; value: string | number }[] +} + +export default function Pulldown({ + label, + helpText, + value, + onChange, + options, +}: PulldownProps) { + return ( + <> + + {helpText &&
{helpText}
} + + ) +} From ead8198e4b3eec96fb20a88da045cc06cc046b53 Mon Sep 17 00:00:00 2001 From: KazumaOhashi Date: Tue, 13 Aug 2024 10:42:39 +0900 Subject: [PATCH 2/4] Add SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST constant --- src/constants.ts | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/constants.ts diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 0000000..11b2da6 --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,55 @@ +export const SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST = [ + { + label: 'text', + value: { + type: 'text', + text: 'Hello, World!', + }, + }, + { + label: 'sticker', + value: { + type: 'sticker', + packageId: '446', + stickerId: '1988', + }, + }, + { + label: 'image', + value: { + type: 'image', + originalContentUrl: 'https://example.com/original.jpg', + previewImageUrl: 'https://example.com/preview.jpg', + }, + }, + { + label: 'video', + value: { + type: 'video', + originalContentUrl: 'https://example.com/original.mp4', + previewImageUrl: 'https://example.com/preview.jpg', + trackingId: 'track-id', + }, + }, + { + label: 'audio', + value: { + type: 'audio', + originalContentUrl: 'https://example.com/original.m4a', + duration: 60000, + }, + }, + { + label: 'location', + value: { + type: 'location', + title: 'my location', + address: '〒102-8282 東京都千代田区紀尾井町1番3号', + latitude: 35.67966, + longitude: 139.73669, + }, + }, +].map(({ label, value }) => ({ + label, + value: JSON.stringify(value, null, 4), +})) From 72a5063eb3813575f34146a13673b48c53511ae7 Mon Sep 17 00:00:00 2001 From: KazumaOhashi Date: Tue, 13 Aug 2024 10:46:01 +0900 Subject: [PATCH 3/4] Change Snippet to accept pulldownOptions and allow selecting the payload --- src/App.tsx | 13 +--- src/components/Snippet.tsx | 139 +++++++++++++++++++++---------------- 2 files changed, 84 insertions(+), 68 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 0de28fa..4193902 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,6 +6,7 @@ import Snippet from './components/Snippet' import Input from './components/Input' import { FilterContext, FilterTypes } from './Context' import qrCode from './qr-code.png' +import { SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST } from './constants' const isMINI = new URLSearchParams(location.search).has('mini') const filter = isMINI ? FilterTypes.MINI : FilterTypes.LIFF @@ -225,16 +226,8 @@ function App() { docUrl="https://developers.line.biz/en/reference/liff/#share-target-picker" needRequestPayload={true} hideResponse={true} - defaultRequestPayload={JSON.stringify( - [ - { - type: 'text', - text: 'Hello, World!', - }, - ], - null, - 4 - )} + defaultRequestPayload={SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST[0].value} + pulldownOptions={SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST} skipAutoRun={true} runner={async (options) => { return await liff.shareTargetPicker(JSON.parse(options)) diff --git a/src/components/Snippet.tsx b/src/components/Snippet.tsx index 7c5b61a..4b8b347 100644 --- a/src/components/Snippet.tsx +++ b/src/components/Snippet.tsx @@ -5,6 +5,7 @@ import styles from './Snippet.module.css' import Tag from './Tag' import TextArea from './TextArea' import { FilterContext, FilterTypes } from '../Context' +import Pulldown from './Pulldown' interface SippetProps { apiName: string @@ -12,6 +13,7 @@ interface SippetProps { docUrl: string needRequestPayload?: boolean defaultRequestPayload?: string + pulldownOptions?: { label: string; value: string }[] useTextareaForResponse?: boolean skipAutoRun?: boolean hideResponse?: boolean @@ -26,9 +28,9 @@ interface RunnerError extends Error { message: string } -const primaryRed = '#eb4e3d'; -const primaryBlue = '#6fedd6'; -const primaryOrange = '#ff9551'; +const primaryRed = '#eb4e3d' +const primaryBlue = '#6fedd6' +const primaryOrange = '#ff9551' export default function Snippet({ apiName, @@ -40,10 +42,11 @@ export default function Snippet({ needRequestPayload, useTextareaForResponse, defaultRequestPayload, + pulldownOptions, loginRequired, inClientOnly, isInLIFF = true, - isInMINI = true + isInMINI = true, }: SippetProps) { const [response, setResponse] = useState('') const [payload, setPayload] = useState(defaultRequestPayload || '') @@ -71,64 +74,84 @@ export default function Snippet({ return ( - { - (filter) => - ((filter === FilterTypes.LIFF && isInLIFF) || (filter === FilterTypes.MINI && isInMINI)) - &&
-
-

- {apiName} - ≥{version} - {loginRequired && Login Required} {inClientOnly && LINE Client only} - {isInLIFF && LIFF} - {isInMINI && MINI} -

-
- {' '} - + {(filter) => + ((filter === FilterTypes.LIFF && isInLIFF) || + (filter === FilterTypes.MINI && isInMINI)) && ( +
+
+

+ {apiName} + ≥{version} + {loginRequired && ( + Login Required + )}{' '} + {inClientOnly && ( + LINE Client only + )} + {isInLIFF && LIFF} + {isInMINI && MINI} +

+
+ {' '} + +
-
- {needRequestPayload && ( -