-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tamim Attafi
committed
Oct 9, 2023
1 parent
02d7e07
commit d1c4ba9
Showing
22 changed files
with
470 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
sample/web/src/components/app/button/DisableMainButton.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import TelegramDetailedButton from "../../kit/DetailedButton/TelegramDetailedButton"; | ||
import {useTelegram} from "../../../hooks/useTelegram"; | ||
|
||
/** | ||
* MainButton.disable() is a method to disable the button. | ||
* | ||
* @see https://core.telegram.org/bots/webapps#mainbutton | ||
*/ | ||
const DisableMainButton = () => { | ||
const {webApp, executeMethod} = useTelegram() | ||
|
||
const onDisable = () => { | ||
executeMethod('MainButton.disable', webApp.MainButton.disable) | ||
} | ||
|
||
return ( | ||
<TelegramDetailedButton | ||
buttontitle={'MainButton.disable()'} | ||
buttondescription={ | ||
'A method to disable the button.' | ||
} | ||
buttonlabel={'Execute'} | ||
onButtomClick={onDisable} | ||
/> | ||
); | ||
}; | ||
|
||
export default DisableMainButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import TelegramDetailedButton from "../../kit/DetailedButton/TelegramDetailedButton"; | ||
import {useTelegram} from "../../../hooks/useTelegram"; | ||
|
||
/** | ||
* MainButton.enable() is a method to enable the button. | ||
* | ||
* @see https://core.telegram.org/bots/webapps#mainbutton | ||
*/ | ||
const EnableMainButton = () => { | ||
const {webApp, executeMethod} = useTelegram() | ||
|
||
const onEnable = () => { | ||
executeMethod('MainButton.enable', webApp.MainButton.enable) | ||
} | ||
|
||
return ( | ||
<TelegramDetailedButton | ||
buttontitle={'MainButton.enable()'} | ||
buttondescription={ | ||
'A method to enable the button.' | ||
} | ||
buttonlabel={'Execute'} | ||
onButtomClick={onEnable} | ||
/> | ||
); | ||
}; | ||
|
||
export default EnableMainButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import TelegramDetailedButton from "../../kit/DetailedButton/TelegramDetailedButton"; | ||
import {useTelegram} from "../../../hooks/useTelegram"; | ||
|
||
/** | ||
* MainButton.hide() is a method to hide the button. | ||
* | ||
* @see https://core.telegram.org/bots/webapps#mainbutton | ||
*/ | ||
const HideMainButton = () => { | ||
const {webApp, executeMethod} = useTelegram() | ||
|
||
const onHide = () => { | ||
executeMethod('MainButton.hide', webApp.MainButton.hide) | ||
} | ||
|
||
return ( | ||
<TelegramDetailedButton | ||
buttontitle={'MainButton.hide()'} | ||
buttondescription={ | ||
'A method to hide the button.' | ||
} | ||
buttonlabel={'Execute'} | ||
onButtomClick={onHide} | ||
/> | ||
); | ||
}; | ||
|
||
export default HideMainButton; |
29 changes: 29 additions & 0 deletions
29
sample/web/src/components/app/button/HideProgressMainButton.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import TelegramDetailedButton from "../../kit/DetailedButton/TelegramDetailedButton"; | ||
import {useTelegram} from "../../../hooks/useTelegram"; | ||
|
||
/** | ||
* MainButton.hideProgress() is a method to hide the loading indicator. | ||
* | ||
* @see https://core.telegram.org/bots/webapps#mainbutton | ||
*/ | ||
const HideProgressMainButton = () => { | ||
const {webApp, executeMethod} = useTelegram() | ||
|
||
const onHideProgress = () => { | ||
executeMethod('MainButton.hideProgress', webApp.MainButton.hideProgress) | ||
} | ||
|
||
return ( | ||
<TelegramDetailedButton | ||
buttontitle={'MainButton.hideProgress()'} | ||
buttondescription={ | ||
'A method to hide the loading indicator.' | ||
} | ||
buttonlabel={'Execute'} | ||
onButtomClick={onHideProgress} | ||
/> | ||
); | ||
}; | ||
|
||
export default HideProgressMainButton; |
32 changes: 32 additions & 0 deletions
32
sample/web/src/components/app/button/SetColorMainButton.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import TelegramDetailedButton from "../../kit/DetailedButton/TelegramDetailedButton"; | ||
import {useTelegram} from "../../../hooks/useTelegram"; | ||
import TelegramMiniForm from "../../kit/MiniForm/TelegramMiniForm"; | ||
|
||
/** | ||
* MainButton.color is the current button color. Set to themeParams.button_color by default. | ||
* | ||
* @see https://core.telegram.org/bots/webapps#mainbutton | ||
*/ | ||
const SetColorMainButton = () => { | ||
const {webApp, executeMethod} = useTelegram() | ||
|
||
const onSetColor = (color) => { | ||
executeMethod( | ||
'MainButton.setColor', | ||
() => { webApp.MainButton.color = color } | ||
) | ||
} | ||
|
||
return ( | ||
<TelegramMiniForm | ||
fieldlabel={'MainButton.color'} | ||
fielddescription={'Current button color. Set to themeParams.button_color by default.'} | ||
fieldhint={`#RRGGBB color, e.g ${webApp.MainButton.color}`} | ||
buttonlabel={'Execute'} | ||
onSubmit={onSetColor} | ||
/> | ||
); | ||
}; | ||
|
||
export default SetColorMainButton; |
45 changes: 45 additions & 0 deletions
45
sample/web/src/components/app/button/SetParamsMainButton.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import TelegramDetailedButton from "../../kit/DetailedButton/TelegramDetailedButton"; | ||
import {useTelegram} from "../../../hooks/useTelegram"; | ||
import TelegramMiniForm from "../../kit/MiniForm/TelegramMiniForm"; | ||
|
||
/** | ||
* MainButton.setParams(params) is a method to set the button parameters. | ||
* | ||
* The params parameter is an object containing one or several fields that need to be changed: | ||
* text - button text; | ||
* color - button color; | ||
* text_color - button text color; | ||
* is_active - enable the button; | ||
* is_visible - show the button. | ||
* | ||
* @see https://core.telegram.org/bots/webapps#mainbutton | ||
*/ | ||
const SetParamsMainButton = () => { | ||
const {webApp, executeMethod} = useTelegram() | ||
|
||
const onSetParams = (text) => { | ||
const json = JSON.parse(text) | ||
executeMethod( | ||
'MainButton.setParams', | ||
() => webApp.MainButton.setParams(json) | ||
) | ||
} | ||
|
||
return ( | ||
<TelegramMiniForm | ||
fieldlabel={'MainButton.setParams(params)'} | ||
fielddescription={'A method to set the button parameters. The params parameter is an object containing one or several fields that need to be changed:\n' + | ||
'text - button text;\n' + | ||
'color - button color;\n' + | ||
'text_color - button text color;\n' + | ||
'is_active - enable the button;\n' + | ||
'is_visible - show the button.'} | ||
fieldhint={`Enter valid json of main button params`} | ||
buttonlabel={'Execute'} | ||
onSubmit={onSetParams} | ||
/> | ||
); | ||
}; | ||
|
||
export default SetParamsMainButton; |
32 changes: 32 additions & 0 deletions
32
sample/web/src/components/app/button/SetTextColorMainButton.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import TelegramDetailedButton from "../../kit/DetailedButton/TelegramDetailedButton"; | ||
import {useTelegram} from "../../../hooks/useTelegram"; | ||
import TelegramMiniForm from "../../kit/MiniForm/TelegramMiniForm"; | ||
|
||
/** | ||
* MainButton.textColor is the current button text color. Set to themeParams.button_text_color by default. | ||
* | ||
* @see https://core.telegram.org/bots/webapps#mainbutton | ||
*/ | ||
const SetTextColorMainButton = () => { | ||
const {webApp, executeMethod} = useTelegram() | ||
|
||
const onSetTextColor = (color) => { | ||
executeMethod( | ||
'MainButton.setTextColor', | ||
() => { webApp.MainButton.textColor = color } | ||
) | ||
} | ||
|
||
return ( | ||
<TelegramMiniForm | ||
fieldlabel={'MainButton.textColor'} | ||
fielddescription={'Current button text color. Set to themeParams.button_text_color by default.'} | ||
fieldhint={`#RRGGBB color, e.g ${webApp.MainButton.textColor}`} | ||
buttonlabel={'Execute'} | ||
onSubmit={onSetTextColor} | ||
/> | ||
); | ||
}; | ||
|
||
export default SetTextColorMainButton; |
32 changes: 32 additions & 0 deletions
32
sample/web/src/components/app/button/SetTextMainButton.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import TelegramDetailedButton from "../../kit/DetailedButton/TelegramDetailedButton"; | ||
import {useTelegram} from "../../../hooks/useTelegram"; | ||
import TelegramMiniForm from "../../kit/MiniForm/TelegramMiniForm"; | ||
|
||
/** | ||
* MainButton.setText(text) is a method to set the button text. | ||
* | ||
* @see https://core.telegram.org/bots/webapps#mainbutton | ||
*/ | ||
const SetTextMainButton = () => { | ||
const {webApp, executeMethod} = useTelegram() | ||
|
||
const onSetText = (text) => { | ||
executeMethod( | ||
'MainButton.setText', | ||
() => webApp.MainButton.setText(text) | ||
) | ||
} | ||
|
||
return ( | ||
<TelegramMiniForm | ||
fieldlabel={'MainButton.setText(text)'} | ||
fielddescription={'A method to set the button text.'} | ||
fieldhint={`Enter button label`} | ||
buttonlabel={'Execute'} | ||
onSubmit={onSetText} | ||
/> | ||
); | ||
}; | ||
|
||
export default SetTextMainButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import TelegramDetailedButton from "../../kit/DetailedButton/TelegramDetailedButton"; | ||
import {useTelegram} from "../../../hooks/useTelegram"; | ||
|
||
/** | ||
* MainButton.show() is a method to make the button visible. | ||
* | ||
* Note that opening the Mini App from the attachment menu hides the main button until the user interacts with the | ||
* Mini App interface. | ||
* | ||
* @see https://core.telegram.org/bots/webapps#mainbutton | ||
*/ | ||
const ShowMainButton = () => { | ||
const {webApp, executeMethod} = useTelegram() | ||
|
||
const onShow = () => { | ||
executeMethod('MainButton.show', webApp.MainButton.show) | ||
} | ||
|
||
return ( | ||
<TelegramDetailedButton | ||
buttontitle={'MainButton.show()'} | ||
buttondescription={ | ||
'A method to make the button visible.' + | ||
'Note that opening the Mini App from the attachment menu hides the main button until the user interacts with the Mini App interface.' | ||
} | ||
buttonlabel={'Execute'} | ||
onButtomClick={onShow} | ||
/> | ||
); | ||
}; | ||
|
||
export default ShowMainButton; |
46 changes: 46 additions & 0 deletions
46
sample/web/src/components/app/button/ShowProgressMainButton.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import TelegramDetailedButton from "../../kit/DetailedButton/TelegramDetailedButton"; | ||
import {useTelegram} from "../../../hooks/useTelegram"; | ||
import TelegramMiniForm from "../../kit/MiniForm/TelegramMiniForm"; | ||
import TelegramMiniFormWithOptions from "../../kit/MiniFormWithOptions/TelegramMiniFormWithOptions"; | ||
import TelegramOptionsForm from "../../kit/OptionsForm/TelegramOptionsForm"; | ||
|
||
/** | ||
* MainButton.showProgress(leaveActive) is a method to show a loading indicator on the button. | ||
* It is recommended to display loading progress if the action tied to the button may take a long time. | ||
* | ||
* By default, the button is disabled while the action is in progress. | ||
* If the parameter leaveActive=true is passed, the button remains enabled. | ||
* | ||
* @see https://core.telegram.org/bots/webapps#mainbutton | ||
*/ | ||
const ShowProgressMainButton = () => { | ||
const {webApp, executeMethod} = useTelegram() | ||
|
||
const onShowProgress = (options) => { | ||
const leaveActive= options[0] === 'true' | ||
executeMethod( | ||
'MainButton.showProgress', | ||
() => webApp.MainButton.showProgress(leaveActive) | ||
) | ||
} | ||
|
||
const options = ['true', 'false'] | ||
|
||
return ( | ||
<TelegramOptionsForm | ||
formlabel={'MainButton.showProgress(leaveActive)'} | ||
formdescription={ | ||
'A method to show a loading indicator on the button.' + | ||
'It is recommended to display loading progress if the action tied to the button may take a long time. By default, the button is disabled while the action is in progress. If the parameter leaveActive=true is passed, the button remains enabled.' | ||
} | ||
optionsmultiple={false} | ||
optionslabel={'leaveActive'} | ||
options={options} | ||
buttonlabel={'Execute'} | ||
onSubmit={onShowProgress} | ||
/> | ||
); | ||
}; | ||
|
||
export default ShowProgressMainButton; |
Oops, something went wrong.